Develop a C++ program with a class named as "area" to find the area of the room and inherit this property into another class named as "volume" to find out the volume of the same room and display both the results
#include<iostream>
using namespace std;
class area
{
private:
float width;
float height;
public:
area(){
this->width=0;
this->height=0;
}
area(float width,float height){
this->width=width;
this->height=height;
}
float areaRoom()
{
return width*height;
}
};
class volume:public area
{
private:
float depth;
public:
volume(){
this->depth=0;
}
volume(float width,float height,float depth):area(width,height){
this->depth=depth;
}
float volumeRoom()
{
return area::areaRoom()*depth;
}
};
int main(){
volume room(4,5,5);
cout<<"Area of the room: "<<room.areaRoom()<<"\n";
cout<<"Volume of the room: "<<room.volumeRoom()<<"\n";
system("pause");
return 0;
}
Comments
Leave a comment