#include #include class Shape { public: virtual void draw() = 0; virtual std::string whoareyou() = 0; }; class Line: public Shape { private: int length; public: Line(int q) { length = q; } void draw() { for (int i = 0; i < length; i++) std::cout << "-"; std::cout << "\n"; } std::string whoareyou() { return "line"; } }; class Rectangle: public Shape { private: int dx, dy; public: Rectangle(int a, int b) { dx = a; dy = b; } void draw() { for (int i = 0; i < dx; i++) { if (i == 0 || i == dx - 1) std::cout << "+"; else std::cout << "|"; for (int j = 1; j < dy - 1; j++) if (i == 0 || i == dx - 1) std::cout << "-"; else std::cout << " "; if (i == 0 || i == dx - 1) std::cout << "+\n"; else std::cout << "|\n"; } } std::string whoareyou() { return "rectangle"; } }; int main() { int a; do { std::cout << "Which shape do you want to draw? "; std::cin >> a; Shape *shape; if (a == 1) { shape = new Line(50); } else if (a == 2) { shape = new Rectangle(10, 40); } else break; shape->draw(); std::cout << shape->whoareyou() << "\n"; delete shape; } while (a != 0); return 0; }