Question: Write a class called Box that has three double fields called height, width and length. The class should have set methods for each field. It

Write a class called Box that has three double fields called height, width and length. The class should have set methods for each field. It should have a three-parameter constructor that takes three doubles and passes them to the set methods to initialize the fields of the Box. It should have a default constructor that uses the set methods to initialize each field to 1. It should have a method that calculates and returns the volume of the Box and a method that calculates and returns the surface area of the Box.

The class declaration (interface) and the function definitions (implementation) must be in separate files - the interface or "header" file has a .hpp extension and the implementation has a .cpp extension. As usual, all data members should be private. The Box class might be used as follows:

Box box1(2.4, 7.1, 5.0); Box box2; double volume1 = box1.calcVolume(); double surfaceArea1 = box1.calcSurfaceArea(); double volume2 = box2.calcVolume(); double surfaceArea2 = box2.calcSurfaceArea(); 

Your functions should have the following names:

setHeight

setWidth

setLength

calcVolume

calcSurfaceArea

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!