#include #include using std::list; using std::cout; using std::endl; #include using std::string; class Shape { public: Shape() : color("lavender") {} Shape(const string& c) : color(c) {} virtual void draw() const = 0; float findArea() const { return 0; } const string& getColor() const { return color; } private: string color; }; class Rectangle : public Shape { public: Rectangle(float l, float w) : Shape(), length(l), width(w) {} Rectangle(const string& c, float l, float w) : Shape(c), length(l), width(w) {} virtual void draw() const { cout << "I'm a Rectangle" << endl; } virtual float findArea() const { return length * width; } private: float length; float width; }; class Circle : public Shape { public: Circle(float r) : radius(r) {} Circle(const string& c, float r) : Shape(c), radius(r) {} virtual void draw() const { cout << "I'm a Circle" << endl; } virtual float findArea() const { return 3.14159*radius*radius; } private: float radius; }; void print(const list & l) { list::const_iterator ptr = l.begin(); while ( ptr != l.end() ) { (*ptr)->draw(); ++ptr; } } int main() { list shapes; Shape *circle = new Circle("Chartreuse", 2); Shape *rectangle = new Rectangle("red", 4,3); shapes.push_back(circle); shapes.push_back(rectangle); Shape *x = new Circle(25); cout << x->getColor() << endl; print(shapes); delete circle; delete rectangle; delete x; return 0; }