Answer to Question #327851 in C++ for josss

Question #327851

Based on the inheritance hierarchy/tree, write a C++ program to get the width, length and




height from users and call the calculateArea() member function of the Calculate




drived class to determine and return the volume of the user’s input. Before the program




ends, display all values read from users and the calculated area.





1
Expert's answer
2022-04-13T07:33:11-0400
#include<iostream>

using namespace std;

class Rectangl
{
	float length;
	float width;
public:
	Rectangl(){}
	void AssignR()
	{
		cout << "Please, enter a length of rectangle: ";
		cin >> length;
		cout << "Please, enter a width of rectangle: ";
		cin >> width;
	}
	float calculateArea()
	{
		return length*width;
	}
	void DisplayR()
	{
		cout << "\nLength of rectangle is " << length
			<< "\nWidth of rectangle is " << width;
	}
};

class Volume:public Rectangl
{
	float height;
	float vol;
public:
	Volume(){}
	Volume(float _height):height(_height){}
	void Assign()
	{
		cout << "Please, enter a height of rectangle: ";
		cin >> height;
	}


	void calculateVolume()
	{
		vol = calculateArea()*height;
	}
	void Display()
	{
		cout << "\nHeight is " << height
			<< "\nVolome is " << vol;
	}
};


int main()
{
	Volume v;
	v.AssignR();
	v.Assign();
	v.calculateVolume();
	v.DisplayR();
	v.Display();
}

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
APPROVED BY CLIENTS