#include #include #include using namespace std; class Shape { public: Shape(int x_pos, int y_pos, char symbol) : x_pos {x_pos}, y_pos{y_pos}, symbol{symbol} { } virtual ~Shape() = default; virtual bool contains(int x, int y) = 0; char get_symbol() const { return symbol; } protected: int x_pos; int y_pos; char symbol; }; class Rectangle : public Shape { public: Rectangle(int x_pos, int y_pos, char symbol, int width, int height) : Shape{x_pos, y_pos, symbol}, width{width}, height{height} { } bool contains(int x, int y) { return (x < x_pos + width && x >= x_pos && y < y_pos + height && y >= y_pos); } private: int width; int height; }; class Circle : public Shape { public: Circle(int x_pos, int y_pos, char symbol, float radius) : Shape{x_pos, y_pos, symbol}, radius{radius} { } bool contains(int x, int y) { double dist {pow(x - x_pos, 2) + pow(y - y_pos, 2)}; return dist < pow(radius, 2); } private: float radius; }; void draw(vector shapes) { int h {40}, w{80}; for(int i {}; i < h; ++i) { for(int j{}; j < w; ++j) { char to_print {' '}; for (Shape* s : shapes) { if (s->contains(j,i*2)) { to_print = s->get_symbol(); } } cout << to_print; } cout << endl; } }; int main() { vector shapes { new Circle{10,70, 'x', 5}, new Circle{20,70, 'x', 5}, new Circle{30,70, 'x', 5}, new Rectangle{5,59, '#', 31,6}, new Rectangle{25,50, '#', 10,10}, new Rectangle{23,44, '#', 14,6}, new Rectangle{10,53, '#', 4,6}, new Circle{12,48, '%', 3}, new Circle{16,36, ';', 6}, new Circle{28,20, '.', 9}, }; draw(shapes); for ( Shape* s : shapes ) { delete s; } }