#include<iostream.h>
#include<conio.h>
class Rectangle
{
public :
float length,breadth;
Rectangle(){}
Rectangle(float t,float t1)
{
length=t;
breadth=t1;
}
void get()
{
cout<<"\n\n\t\tEnter the Length of the Rectangle :";
cin>>length;
cout<<"\n\n\t\tEnter the Breadth of the Rectangle : ";
cin>>breadth;
}
virtual void calculate()
{ /* fn. to calculate perimeter*/
float p=2.0;
float k=length+breadth;
p=p*k;
cout<<"\n\n\tPERIMETER OF THE RECTANGLE : "<<p;
}
};
class Area : public Rectangle
{
public:
void calculate()
{
/*fn. to return area of the rectangle*/
cout<<"\n\n\tAREA OF THE RECTANGLE : "<<length*breadth;
}
};
void main()
{
clrscr();
cout<<"\n\n\tPROGRAM TO CALCULATE AREA & PERIMETER OF THE RECTANGLE\n\n";
Area area;//derived
Rectangle *ptr;//base
ptr=&area;
ptr->get();
ptr->calculate();
Rectangle rect(ptr->length,ptr->breadth);
ptr=▭
ptr->calculate();
getch();
}