Answer to Question #191906 in C++ for VARUN

Question #191906

Create the class Box with attributes length, breath and height to find the volume of a box. Assign the values for data members using copy constructor and display the result. Finally free the resources of data objects using destructor member function. (Note: Volume of a box = length * breath * height)

RUN TIME INPUT:

5.2

3.3

15.5

Output :

265.98



1
Expert's answer
2021-05-13T03:15:37-0400
#include <iostream>
using namespace std;
class Box{
private:
	float length;
	float breadth;
	float height;


public:
	Box(float l, float w, float h){
		this->length = l;
		this->breadth = w;
		this->height = h;
	}
	float calculateVolume(){
		return length *breadth  *height;
	}
	Box(const Box &otherBox){
		this->length = otherBox.length;
		this->breadth = otherBox.breadth;
		this->height = otherBox.height;
	}
	~Box(){


	}
};
int main(){
	float length;
	float breadth;
	float height;
	
	cin>>length;
	cin>>breadth;
	cin>>height;
	Box* box1=new Box(length, breadth, height);


	cout<<box1->calculateVolume()<<"\n";
	


	delete box1;
	


	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