C++ Programming Exercise Skill Based Test (Calculate Box Volume)


A box can be represented by its dimensions, width, length and height. Then, the volume of the box is calculated by multiplying the dimensions, i.e., volume = width x length x height. Complete the source code file, sbt1.cpp, according to the following tasks:

1. Define a class named Box which consists of a. all the required attributes representing the dimensions,                    (3 marks) b. constructors (or a constructor with default arguments),                    (4 marks) c. mutators,                                                                                            (6 marks) d. accessors, and                                                                                    (6 marks) e. a method that calculates the volume.                                                 (3 marks)

2. Complete the definition of function  printBox.  This function prints the dimensions and volume of a box.                                                                                      (4 marks)

3. Create an array to hold 5 boxes and initliize the first and second boxes with specified dimensions.                                                                                                     (4 marks)

4. Using a loop, set the dimensions the remaining boxes with values entered from the keyboard.                                                                                                        (7 marks)

5. Using the function printBox and another loop, print all the boxes.          (3 marks)

6. Calculate and print the total volume of all boxes.                                         (5 marks)

The following figure shows what your program should look like when it runs. Note that, the bold texts indicate keyboard input entered by the user.



Post a Comment

0 Comments