// Using Geometrical shapes to demonstarte polymorphism // RJB Botting April 2009 /* All geometic shapes have a formula for calculating its area and its perimeter.... but the actual formula variaes between the shapes .... */ #include #include #include #include #include using namespace std; class Point { public: double x,y; Point(double x0,double y0):x(x0),y(y0){} virtual void print(){cout << "Point("<< x << ", " << y << ")"; } }; class Shape { public: virtual double perimeter()=0; virtual double area()=0; virtual void print()=0; }; class Square : public Shape { double side; Point bottomLeft; public: Square (double s, Point bl):side(s),bottomLeft(bl){} double perimeter(){ return 4*side;} double area() { return side*side; } void print() { cout << "Square( side = " << side << ", bottomLeft = "; bottomLeft.print(); cout << ")"; } }; const double PI = 4.0*atan(1.0); int main() { Square a (2, Point(0,0)); a.print(); cout << ", Area =" <