我有我的班级:
class Rectangle : public TwoDim
{
public:
void fun() {};
void printShape();
Rectangle(int x1, int y1, int height1, int width1)
{
x = x1;
y = y1;
height = height1;
width = width1;
}
};
打印它的功能:
void Rectangle::printShape()
{
{
cout << "+";
for (int i = 0; i < width - 2; i++)
{
cout << "-";
}
cout << "+\n";
for (int i = 0; i < height - 2; i++)
{
cout << "|";
for (int j = 0; j < +width - 2; j++)
{
cout << " ";
}
cout << "|\n";
}
cout << "+";
for (int i = 0; i < width - 2; i++)
{
cout << "-";
}
cout << "+\n";
}
}
如何更改我的功能,以便从点(x, y)
开始绘制矩形?
非常感谢
答案 0 :(得分:1)
我首先在实际打印之前输出y
std::endl
,然后在有效打印每一行之前输出x
" "
。