Answer to Question #191962 in C++ for VARUN

Question #191962

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



1
Expert's answer
2021-05-14T23:08:23-0400
#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;
}

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