//BCA Support
//www.bcasupport.xyz
#include <iostream.h>
#include <conio.h>
#include <math.h>
class shape
{
public:
virtual void getdata() {}
virtual void displayarea() {}
};
class rectangle: public shape
{
float recside1,recside2;
public:
void getdata()
{
cout<<"\nEnter rectangle side 1 : ";
cin>>recside1;
cout<<"Enter rectangle side 2 : ";
cin>>recside2;
}
void displayarea()
{
cout<<"\nArea of rectangle : "<<recside1*recside2<<" sq. units";
}
};
class triangle: public shape
{
float recside1,recside2,triside1,triside2,triside3,s,area;
public:
void getdata()
{
cout<<"\nEnter triangle side 1 : ";
cin>>triside1;
cout<<"Enter triangle side 2 : ";
cin>>triside2;
cout<<"Enter triangle side 3 : ";
cin>>triside3;
}
void displayarea()
{
s=(triside1+triside2+triside3)/2;
area=s*(s-triside1)*(s-triside2)*(s-triside3);
area=sqrt(area);
cout<<"\nArea of triangle : "<<area<<" sq. units";
}
};
int main()
{
clrscr();
shape s1,*ptr;
rectangle r1;
triangle t1;
ptr=&r1;
ptr->getdata();
ptr=&t1;
ptr->getdata();
clrscr();
ptr=&r1;
ptr->displayarea();
ptr=&t1;
ptr->displayarea();
getch();
return 0;
}
1 Response
Write a comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.