#include <iostream>
using namespace std; 

class Polygon {
 public: 
 Polygon()
 {
 }
 
 virtual void display()
 {
  cout << "   Generic Polygon" << endl; 
 }
 
 virtual int calcArea()
 {
  return 0; 
 }
};

class Rectangle : public Polygon {
 
 private: int width; int length; 
 public: 
 Rectangle( int w, int l )
 {
  width = w; length = l; 
 }
 
 void display()
 {
  cout << "Rectangle" << endl; 
  cout << "   Width: " << width << endl; 
  cout << "   Length: " << length << endl; 
 }
 
    int calcArea()
 {
  return width * length; 
 }
};

class Triangle : public Polygon {
 
 private: int base; int height; 
 public: 
 Triangle( int b, int h )
 {
  base = b; height = h; 
 }
 
 void display()
 {
   cout << "Triangle: " << endl; 
   cout << "   Base: " << base << endl; 
   cout << "   Height: " << height << endl; 
 }
 
     int calcArea()
 {
  return ( 0.5 * base * height ); 
 }
};

int main()
{
 Polygon *polygon[4] = { new Triangle(10, 20), 
                    new Rectangle(20, 20), 
        new Polygon(), 
        new Rectangle(15, 10)
         }; 
 int totalarea = 0; 
 
 for ( int i = 0; i < 4; i++ )
 {
  cout << "Polygon #" << i + 1 << endl; 
  polygon[i]->display();
  cout << "   Area: " << polygon[i]->calcArea();
  totalarea = totalarea + polygon[i]->calcArea(); 
  cout << endl << endl;
 }
 
 cout << "The total area of all polygons: " << totalarea;
 return 0; 
}
