我有一个打印出正方形行的构造函数。如果布尔值为true,则将其打印为填充,如果布尔值为false,则将其打印为空心。这项工作。但是= *(我还有另一个函数说是否空心或填充。它始终打印填充.....
Box::Box(int _width, int _height, bool filled)
{
if (filled)
{
for (int i = 0; i < _height; i++)
{
cout << "x";
for (int j = 1; j < _width; j++)
{
cout << "x";
}
cout << std::endl;
}
}
else if (!filled);
{
for (int i = 0; i < _height; i++)
{
if (i != 0 && i != _height - 1)
{
cout << "x";
for (int j = 1; j < _width-1; j++)
{
cout << " ";
}
cout << "x";
}
else
{
for (int _longrow = 0; _longrow < _width; _longrow++)
{
cout << "x";
}
}
cout << std::endl;
}
}
}
string Box::type() const
{
if (filled)
{
return "Filled";
}
else if (!filled)
{
return "Hollow";
}
}
最佳答案
Box::Box(int _width, int _height, bool afilled)
{
mfilled = afilled;
if (mfilled)