#ifndef __shape_h__ #define __shape_h__ #include using namespace std; struct Point { double x; double y; Point(double a=0.0, double b=0.0) { x = a; y = b; } }; inline ostream & operator <<(ostream & os, const Point & p) { os << '(' << p.x << ", " << p.y << ')'; return os; } struct RGB { unsigned char red; unsigned char green; unsigned char blue; RGB(char r=0, char g=0, char b=0) { red = r; green = g; blue = b; } }; inline ostream & operator <<(ostream & os, const RGB & c) { os << '[' << int(c.red) << ", " << int(c.green) << ", " << int(c.blue) << ']'; return os; } class Shape { Point center; RGB color; double angle; public: Shape(Point p, RGB c, double a) { center = p; color = c; angle = a; } void move(Point new_center) { center = new_center; } virtual void rotate(double new_angle) { angle = new_angle; } const Point & get_center() const { return center; } const RGB & get_color() const { return color; } double get_angle() const { return angle; } virtual void draw() =0; virtual void erase() =0; }; class Square : public Shape { double side; public: Square(Point p, RGB c, double a, double s) : Shape(p, c, a) { side = s; } void draw() { cout << "Square::draw, center=" << get_center() << ", color=" << get_color() << ", angle=" << get_angle() << ", side=" << side << endl; } void erase() { cout << "Square::erase, center=" << get_center() << ", color=" << get_color() << ", angle=" << get_angle() << ", side=" << side << endl; } }; class Circle : public Shape{ double radius; public: Circle(Point p, RGB c, double a, double r) : Shape(p, c, a) { radius = r; } void draw() { cout << "Circle::draw, center=" << get_center() << ", color=" << get_color() << ", angle=" << get_angle() << ", radius=" << radius << endl; } void erase() { cout << "Circle::erase, center=" << get_center() << ", color=" << get_color() << ", angle=" << get_angle() << ", radius=" << radius << endl; } void rotate(double new_angle) { } }; class Triangle : public Shape { double side1; double side2; double side3; public: Triangle(Point p, RGB c, double a, double s1, double s2, double s3) : Shape(p, c, a) { side1 = s1; side2 = s2; side3 = s3; } void draw() { cout << "Triangle::draw, center=" << get_center() << ", color=" << get_color() << ", angle=" << get_angle() << ", sides=" << side1 << ", " << side2 << ", " << side3 << endl; } void erase() { cout << "Triangle::erase, center=" << get_center() << ", color=" << get_color() << ", angle=" << get_angle() << ", sides=" << side1 << ", " << side2 << ", " << side3 << endl; } }; class Rectangle : public Shape { double side1; double side2; public: Rectangle(Point p, RGB c, double a, double s1, double s2) : Shape(p, c, a) { side1 = s1; side2 = s2; } int draw(double scale) { cout << "Rectangle::draw, center=" << get_center() << ", color=" << get_color() << ", angle=" << get_angle() << ", sides=" << side1 << ", " << side2 << endl; } void cancella() { cout << "Rectangle::erase, center=" << get_center() << ", color=" << get_color() << ", angle=" << get_angle() << ", sides=" << side1 << ", " << side2 << endl; } }; #endif