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
#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;
}
Comments
Leave a comment