OOP/CPP program to demonstrate inheritance in area of shapes

#include<iostream>
using namespace std;
#include<conio.h>
class area_cl
{
    public:
double height;
double width;
};
class rectangle : public area_cl
{
    public:
rectangle(double h,double w){height=h;width=w;}
double area(){return height*width;}
};
class isosceles : public area_cl
{
  public:
isosceles(double h,double w){height=h;width=w;}
double area(){return 0.5*height*width;}
};
class cylinder : public area_cl
{
  public:
float r;
cylinder(double h,float x){height=h;r=x;}
double area(){return 2*3.141569*r*r + 2*3.141569*r*height;}
};
int main()
{
  cout<<“Calculate the area\n=====================\n\n\n”;
  float r;
  cout<<“\nEnter Radius = “;
  cin>>r;
  double h,w;
  cout<<“\nEnter Height = “;
  cin>>h;
  cout<<“\nEnter Width = “;
  cin>>w;
  rectangle  ob1(h,w);
  isosceles  ob2(h,w);
  cylinder   ob3(h,r);
  cout<<“\n\n\nArea  of rectangle = “<<ob1.area();
  cout<<“\nArea of isosceles  = “<<ob2.area();
  cout<<“\nArea of cylinder   = “<<ob3.area();
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>