#include <iostream>

using namespace std;

class Polygon {
  public:
    Polygon(int w = 0, int h = 0);
    void set(int w, int h);
    virtual float area() const { return 0; };
//    virtual float area() const = 0;   // try  this instead
  protected:
    int width;
    int height;
};

class Rectangle: public Polygon {
  public:
    Rectangle(int w = 0, int h = 0) : Polygon(w, h) {};
    float area() const;
};

class Triangle: public Polygon {
  public:
    Triangle(int w = 0, int h = 0) : Polygon(w, h) {};
    float area() const;
};


Polygon::Polygon(int w, int h) {
    this->set(w, h);
}

void Polygon::set(int w, int h) {
    this->width = w;
    this->height = h;
}
 

float Rectangle::area() const {
    return this->width * this->height;
}     
      
float Triangle::area() const {
    return this->width * this->height / 2;
}     

      
int main () {
  Rectangle r;
  Triangle t;
//  Polygon p; // ERROR
  Polygon *tab[10];
  
  r.set(4, 5);
  t.set(4, 5);

  tab[0] = &r;
  tab[1] = &t;
  tab[2] = new Rectangle(2,2);
  tab[3] = new Triangle(5,10);
  
  for (int i = 0; i < 4; i++) {
    cout << i << ": " << tab[i]->area() << endl;
  }

  delete tab[2];
  delete tab[3];
  
  return 0;
}
