#include using namespace std; class Shape { public: virtual void area() = 0; virtual void name() { cout << "This is a shape" << endl; } virtual ~Shape() {} }; class Circle : public Shape { float r; public: Circle(float x) { r = x; } void name() { cout << "This is a circle" << endl; } void area() { cout << "Area = " << 3.14 * r * r << endl; } }; class Rectangle : public Shape { float l, b; public: Rectangle(float x, float y) { l = x; b = y; } void name() { cout << "This is a rectangle" << endl; } void area() { cout << "Area = " << l * b << endl; } }; class Triangle : public Shape { float b, h; public: Triangle(float x, float y) { b = x; h = y; } void area() { cout << "Area = " << 0.5 * b * h << endl; } }; int main() { float r, l, b, tb, h; cout << "Enter radius of circle: "; cin >> r; cout << "Enter length and breadth of rectangle: "; cin >> l >> b; cout << "Enter base and height of triangle: "; cin >> tb >> h; Shape *s[3]; s[0] = new Circle(r); s[1] = new Rectangle(l, b); s[2] = new Triangle(tb, h); cout << endl; for (int i = 0; i < 3; i++) { s[i]->name(); s[i]->area(); cout << endl; } for (int i = 0; i < 3; i++) delete s[i]; return 0; }