#include <iostream>
using namespace std;
class Shape
{
public:
Shape() {}
~Shape() {}
virtual float GetArea() { return -1; }
};
class Circle : public Shape
{
public :
Circle(float radius):itsRadius(radius){}
~Circle () {}
virtual float GetArea() {
return 3.14 * itsRadius * itsRadius;
}
private :
float itsRadius;
};
class Rectangle : public Shape
{
public :
Rectangle(float a, float b):itsa(a),itsb(b){}
~Rectangle() {}
virtual float GetArea() {
return itsa * itsb;
}
private:
float itsa, itsb;
};
class Square : public Rectangle
{
public:
Square(float len);
~Square() {}
};
Square::Square(float len) :Rectangle(len, len)
{
}
int main()
{
Shape* sp;
sp = new Circle(5);
cout << "The area of the Circle is " << sp->GetArea() << endl;
delete sp;
sp = new Rectangle(4, 6);
cout << "The area of the Rectangle is " << sp->GetArea() << endl;
delete sp;
sp = new Square(5);
cout << "The area of the Square is " << sp->GetArea() << endl;
delete sp;
}