Name: _____________________                                                                                           September 24, 2003

Queens College, CS211                                                                                                           Instructor:  Bo Zhang

 

Quiz #1, Version F

 

Directions:  Answer the question by writing code to solve the following problem.  You should answer this quiz directly on the paper, using a pen.  If you need extra space, you may use a sheet of your own paper.  However, please make sure that any extra paper that you submit has your name written on every page, and is stapled to the quiz.

 

Note:  This quiz is open book/open notes

 

For this quiz, you will be asked to design (declare) and implement (define) a class, Box, that models certain properties of the object box.  You will also be asked to write a function that uses this box in the way described below:

 

1.  Write a complete .h file for the class Box.  It should contain the width, length and height of the box.  In addition, it should have a constructor that can set all the variable values, accessor functions for all three variables, mutator functions for all three variables, and a function that returns the volume of the box (see below for more detail), and any other functions that are necessary in the class.

 

2.  Write portions of the .cpp file for this class, implementing the following functions:

A:  The 3 parameter constructor

B:  The mutator function for the length (note that length cannot be less than 0)

C:  The function that returns the volume of the box.  Note that volume is computed by multiplying length by width and by height.

 

It is not required for you to provide code for the other functions in the .cpp file.

 

3.  Write a function that accepts as its parameters an array of boxes and the length of the array.  It returns the total volume of all the boxes.