Calculating area of triangle and rectangle using multiple inheritance in C++
#include <iostream>
using namespace std;
class Shape {
protected: int l,b,a;
public: void getData() {
cout<<"Enter the value of l and b:";
cin>>l>>b;
}
};
class Triangle: public Shape{
public: void display(){
a=(l*b)/2;
cout<<"Area of triangle:"<<a;
}
};
class Rectangle:public Shape{
public:
void display(){
a=l*b;
cout<<"Area of Rectangle:"<<a;
}
};
int main()
{
Rectangle rectangle;
Triangle triangle;
rectangle.getData();
triangle.getData();
rectangle.display();
cout<<endl;
triangle.display();
return 0;
}
Comments
Post a Comment