初学者c++;画室计划 新的C++,所以如果我有任何错误,请不要嘲笑我。我正试图写一个程序,将提请要求用户的单位,然后画房子使用函数。我遇到的问题是我的drawcone函数,这里是我到目前为止的进展 #include<iostream> using namespace std; void drawcone(int height); void drawHorizontalLine(int numXs); void draw2VerticalLines(int numSpaces, int numRows); void drawOneRow(int numSpaces); void getDimensions(int& width, int& height); void drawbox(int width, int height); int main(){ int width; int height; getDimensions(height, width); drawcone(height); drawHorizontalLine(width); draw2VerticalLines(width - 2, height - 2); drawHorizontalLine(width); return 0; } void drawbox(int width, int height){ drawHorizontalLine(width); draw2VerticalLines(width - 2, height - 2); drawHorizontalLine(width); } void drawcone(int height){ int base = height * 2; int r = 0; while ( r != height){ int c = 0; while (c != base){ if(c==height-r || c==height+r) cout << "X"; else cout << " "; c++; } cout << endl; r++; } } void drawHorizontalLine(int numXs) { int count; for (count = 0; count < numXs; count++){ cout << "X"; } cout << endl; } void draw2VerticalLines(int numSpaces, int numRows) { int rowCount; for (rowCount = 0; rowCount < numRows; rowCount++){ drawOneRow(numSpaces); } } void drawOneRow(int numSpaces) { int spaceCount; cout << "X"; for (spaceCount = 0; spaceCount < numSpaces; spaceCount++){ cout << " "; } cout << "X" << endl; } void getDimensions(int& width, int& height){ cout << "Enter the width of the house" << endl; cin >> width; cout << "Enter the height of the house" << endl; cin >> height; }
我当前的输出如下所示初学者c++;画室计划 新的C++,所以如果我有任何错误,请不要嘲笑我。我正试图写一个程序,将提请要求用户的单位,然后画房子使用函数。我遇到的问题是我的drawcone函数,这里是我到目前为止的进展 #include<iostream> using namespace std; void drawcone(int height); void drawHorizontalLine(int numXs); void draw2VerticalLines(int numSpaces, int numRows); void drawOneRow(int numSpaces); void getDimensions(int& width, int& height); void drawbox(int width, int height); int main(){ int width; int height; getDimensions(height, width); drawcone(height); drawHorizontalLine(width); draw2VerticalLines(width - 2, height - 2); drawHorizontalLine(width); return 0; } void drawbox(int width, int height){ drawHorizontalLine(width); draw2VerticalLines(width - 2, height - 2); drawHorizontalLine(width); } void drawcone(int height){ int base = height * 2; int r = 0; while ( r != height){ int c = 0; while (c != base){ if(c==height-r || c==height+r) cout << "X"; else cout << " "; c++; } cout << endl; r++; } } void drawHorizontalLine(int numXs) { int count; for (count = 0; count < numXs; count++){ cout << "X"; } cout << endl; } void draw2VerticalLines(int numSpaces, int numRows) { int rowCount; for (rowCount = 0; rowCount < numRows; rowCount++){ drawOneRow(numSpaces); } } void drawOneRow(int numSpaces) { int spaceCount; cout << "X"; for (spaceCount = 0; spaceCount < numSpaces; spaceCount++){ cout << " "; } cout << "X" << endl; } void getDimensions(int& width, int& height){ cout << "Enter the width of the house" << endl; cin >> width; cout << "Enter the height of the house" << endl; cin >> height; },c++,function,void,C++,Function,Void,我当前的输出如下所示 X X X X X XXXXX X X X X XXXXX X X X X X X X XXXX X X X X XXXX 我希望圆锥体稍微小一点,这样它将与盒子成比例。我还希望答案不涉及修改drawbox功能。谢谢你抽出时间 应该很容易调试,因为它打印出了房子“屋顶”的错误空间数。 问题应包含在while(r!=高度)块中 试着弄乱或者{cout这里有一个解决方案。然而,只有当宽度为奇数时,圆锥体才会
X
X X
X X
XXXXX
X X
X X
XXXXX
X
X X
X X
X X
XXXX
X X
X X
XXXX
我希望圆锥体稍微小一点,这样它将与盒子成比例。我还希望答案不涉及修改
drawbox
功能。谢谢你抽出时间 应该很容易调试,因为它打印出了房子“屋顶”的错误空间数。
问题应包含在while(r!=高度)
块中
试着弄乱
或者{cout这里有一个解决方案。然而,只有当宽度为奇数时,圆锥体才会对称
#include<iostream>
using namespace std;
void drawcone(int height);
void drawHorizontalLine(int numXs);
void draw2VerticalLines(int numSpaces, int numRows);
void drawOneRow(int numSpaces);
void getDimensions(int& width, int& height);
void drawbox(int width, int height);
int main() {
int width;
int height;
getDimensions(width, height);
drawcone(width);
drawHorizontalLine(width);
draw2VerticalLines(width - 2, height - 2);
drawHorizontalLine(width);
return 0;
}
void drawbox(int width, int height) {
drawHorizontalLine(width);
draw2VerticalLines(width - 2, height - 2);
drawHorizontalLine(width);
}
void drawcone(int width) {
for (int i=0; i<(width/2 + width%2); i++) {
for (int j=width/2-i; j>0; j--) {
cout << " ";
}
drawOneRow(i*2-1);
}
}
void drawHorizontalLine(int numXs)
{
int count;
for (count = 0; count < numXs; count++) {
cout << "X";
}
cout << endl;
}
void draw2VerticalLines(int numSpaces, int numRows)
{
int rowCount;
for (rowCount = 0; rowCount < numRows; rowCount++) {
drawOneRow(numSpaces);
}
}
void drawOneRow(int numSpaces)
{
int spaceCount;
cout << "X";
if (numSpaces > 0) {
for (spaceCount = 0; spaceCount < numSpaces; spaceCount++) {
cout << " ";
}
cout << "X";
}
cout << endl;
}
void getDimensions(int& width, int& height) {
cout << "Enter the width of the house" << endl;
cin >> width;
cout << "Enter the height of the house" << endl;
cin >> height;
}
#包括
使用名称空间std;
空心抽油锥(内部高度);
空抽水平线(整数mxs);
void draw2verticalline(int numSpaces,int numRows);
void drawOneRow(int numSpaces);
尺寸(内部和宽度、内部和高度);
空抽屉(内部宽度、内部高度);
int main(){
整数宽度;
内部高度;
获取尺寸(宽度、高度);
拉锥(宽度);
图纸水平线(宽度);
图纸2垂直线(宽度-2,高度-2);
图纸水平线(宽度);
返回0;
}
空抽屉(内部宽度、内部高度){
图纸水平线(宽度);
图纸2垂直线(宽度-2,高度-2);
图纸水平线(宽度);
}
空心抽油锥(内部宽度){
对于(int i=0;i0;j--){
不能包含
使用名称空间std;
空心屋顶(内部高度);
void hLine(int num);
虚线(整数空间,整数行);
空行(int空格);
空隙尺寸(内部和宽度、内部和高度);
空框(整数宽度、整数高度);
int main()
{
整数宽度;
内部高度;
尺寸(高度、宽度);
屋顶(高度);
hLine(宽度);
垂直线(宽-2,高-2);
hLine(宽度);
返回0;
}
空框(整数宽度、整数高度)
{
hLine(宽度);
垂直线(宽-2,高-2);
hLine(宽度);
}
空心屋顶(内部高度)
{
内底=高度*2;
int r=0;
while(r!=高度)
{
int c=0;
while(c!=base)
{
如果(c==高度-r | c==高度+r)
使用调试器单步执行代码能告诉您是什么导致了问题吗?当调用getDimensions时,宽度和高度的顺序错误,因此这些值将被触发。另一个问题是,您假设屋顶的底部是高度的两倍,而只要稍微看一眼正确的输出就会表明它是我的不知道。你已经知道屋顶应该有多宽了——高度不得而知。(但你不需要计算它的高度。)我不确定你的意思。我还是个新手。你能再解释一下吗?
#include<iostream>
using namespace std;
void roof(int height);
void hLine(int num);
void vLine(int spaces, int rows);
void row(int spaces);
void dimensions(int& width, int& height);
void box(int width, int height);
int main()
{
int width;
int height;
dimensions(height, width);
roof(height);
hLine(width);
vLine(width - 2, height - 2);
hLine(width);
return 0;
}
void box(int width, int height)
{
hLine(width);
vLine(width - 2, height - 2);
hLine(width);
}
void roof(int height)
{
int base = height * 2;
int r = 0;
while ( r != height)
{
int c = 0;
while (c != base)
{
if(c==height-r || c==height+r)
cout << "*";
else
cout << " ";
c++;
}
cout << endl;
r++;
}
}
void hLine(int num)
{
int count;
for (count = 0; count < num*2+1; count++)
{
cout << "-";
}
cout << endl;
}
void vLine(int spaces, int rows)
{
int numrows;
for (numrows = 0; numrows < rows; numrows++)
{
row(spaces);
}
}
void row(int spaces)
{
int numspaces;
cout << "{";
for (numspaces = 0; numspaces < spaces*2+3; numspaces++)
{
cout << "$";
}
cout << "}" << endl;
}
void dimensions(int& width, int& height)
{
cout<<"Enter the width of the house"<<endl;
cin>>width;
cout<<"Enter the height of the house"<<endl;
cin>>height;
}