// dynamic allocation and polymorphism #include using namespace std; class Polygon { protected: int width, height; public: void set_values (int a, int b) { width=a; height=b; } virtual int area (void) =0; void printarea (void) { cout << "The area is " << this->area() << endl; } }; class Rectangle: public Polygon { public: int area (void) { return (width * height); } }; class Triangle: public Polygon { public: int area (void) { return (width * height / 2); } }; int main () { Polygon *poly1 = new Rectangle; Polygon *poly2 = new Triangle; poly1->set_values (4,5); poly2->set_values (4,5); poly1->printarea(); poly2->printarea(); delete poly1; delete poly2; getchar(); return 0; }