// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;
class shape
{
public:
int area;
virtual void calculatearea() = 0;
virtual void printarea() = 0;
};
class Rectangle : public shape
{
public:
int len;
int breadth;
Rectangle(int l, int b) : len(l),breadth(b) {}
void calculatearea()
{
area = len*breadth;
}
void printarea()
{
cout<<"Area of Rectangle : "<<area<<endl;
}
};
class Square : public Rectangle
{
public:
Square(int val) : Rectangle(val,val) {}
void calculatearea()
{
area = len*breadth;
}
void printarea()
{
cout<<"Area of Square : "<<area<<endl;
}
};
class Triangle : public shape
{
public:
int base;
int height;
Triangle(int b, int h) : base(b),height(h) {}
void calculatearea()
{
area = 0.5 * base * height;
}
void printarea()
{
cout<<"Area of Triangle : "<<area<<endl;
}
};
int main() {
// Write C++ code here
int len,brth,side,base,height;
cout<<"enter the length : "<<endl;
cin>>len;
cout<<"enter the breadth : "<<endl;
cin>>brth;
shape *R = new Rectangle(len,brth);
R->calculatearea();
R->printarea();
cout<<"enter the side : "<<endl;
cin>>side;
shape *S = new Square(side);
S->calculatearea();
S->printarea();
cout<<"enter the base : "<<endl;
cin>>base;
cout<<"enter the height : "<<endl;
cin>>height;
shape *T = new Triangle(base,height);
T->calculatearea();
T->printarea();
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: