简体   繁体   English

C ++绘制矩形位置

[英]C++ draw rectangle position

I have my class: 我上课:

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;

    }

};

And the function to print it: 和打印它的功能:

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";
    }

}

How do I change my function such that I will draw the rectangle starting from the point (x, y) ? 如何更改功能,以便从点(x, y)开始绘制矩形?

Thanks a lot 非常感谢

我将从在实际打印之前输出y std::endl s开始,然后在有效打印每一行之前输出x " "

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM