#include using namespace std; class Shape { protected: int width, height; public: Shape() { width = height = 0; } Shape(int w, int h) { width = w; height = h; } virtual void display() const; }; void Shape::display() const { cout << width << " " << height << endl; } class Rectangle : public Shape { public: Rectangle() {} Rectangle(int w, int h) : Shape(w, h) { } int perimeter() const; void display() const; }; int Rectangle::perimeter() const{ return 2 * width + 2 * height; } void Rectangle::display() const { cout << "I am rectangle of width " << width << " and height " << height << endl; } class Triangle: public Shape { public: Triangle() {} Triangle(int w, int h) : Shape(w,h) {} void display() const; }; void Triangle::display() const { cout << "I am triangle of side " << width << endl; } int main() { Shape* a[4]; a[0] = new Rectangle(3,4); a[1] = new Triangle(5,7); a[2] = new Rectangle(10,5); a[3] = new Triangle(2,8); for (auto e: a) { e->display(); } }