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)
Runtime Input :
5.2
3.3
15.5
Output :
265.98
#include <iostream>
using namespace std;
class Box{
float length, breadth, height;
public:
Box()
{
cout<<"Length : ";
cin>>length;
cout<<"Breadth : ";
cin>>breadth;
cout<<"Height : ";
cin>>height;
}
Box(Box &obj)
{
length = obj.length;
height = obj.height;
breadth = obj.breadth;
}
float Volume()
{
return length*breadth*height;
}
~Box()
{
}
};
int main(){
Box A;
Box B=A;
cout<<"\nVolume : "<<B.Volume();
return 0;
}
Comments
Leave a comment