Monday 8 April 2013

C++ Program To Illustrate Multiple Inheritence


#include<iostream.h>
#include<conio.h>
class shape
{
protected:double x;
double y;
public: void getdata()
{
cin>>x>>y;
}
virtual void displayarea(){};
};
class triangle:public shape
{
double area;
public:void displayarea()
{
area=0.5*x*y;
cout<<"area of triangle is:"<<area<<endl;
}
};
class rectangle:public shape
{
double area;
public: void displayarea()
{
area=x*y;
cout<<"area of a rectangle is:"<<area<<endl;
}
};
void main()
{
shape *s;
triangle t;
rectangle r;
clrscr();
cout<<"\nenter the values to find area of triangle\n";
s=&t;
s->getdata();
s->displayarea();
cout<<"\nenter the values to find area of rectangle\n";
s=&r;
s->getdata();
s->displayarea();
getch();
}

No comments:

Post a Comment