A program to demonstrate single inheritance in C++

#include<iostream>
#include<conio.h>
using namespace std;
class Room
{
protected:
int length, breadth;
public:
int Area()
{
return(length*breadth);
}
};
class Bedroom:public Room
{
int height;
public:
void setdata(int l, int b, int h)
{
length=l;
breadth=b;
height=h;
}
int volume()
{
return(length*breadth*height);
}
};
main()
{
int l,b,h;
Bedroom br;
cout<<“enter length, breadth and height of the room:”;
cin>>l>>b>>h;
br.setdata(l, b, h);
cout<<“Area:”<<br.Area();
cout<<“Volume:”<<br.volume();
getch();
}

Output:

Leave a Reply

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