Answer to Question #297374 in C++ for Rajen

Question #297374

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

1
Expert's answer
2022-02-13T13:00:36-0500




#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog