Program #7 - Colorado Mesa University

advertisement
Computer Science I
Program #7
Due December 9, 2015
In this program, we will create a class with data and function members. Then, we will use that class
to solve a simple problem.
1) Create a class named BoxClass. It will include the following parts:
A) Three private data members, all of type double: length, width and height.
B) Two constructors will be created. One is a default constructor, which sets the length,
width and height all to 0.0. The other constructor will have three formal parameters of
type double, which will set the objects length, width and height to those parameters’ values.
C) A printem method which has one formal parameter (an output file). The print method
will print the data to the output file in the following format (note the data are sample
values):
The object has these dimensions :
Length = 4.128 inches
Width = 3.667 inches
Height = 5.111 inches
D) Every variable will need a “get” and a “set” method so that its value can be set or
returned to the program to use. The “get” methods return values of type double, the “set”
methods are void functions which take a parameter of type double.
E) A method which will return the volume of the box in in3.
F) A method which will return the volume of the box in ft3.
G) A method which will return the surface area of the box in in2.
H) A method which will return the surface area of the box in ft2.
2) Use the BoxClass by following these steps:
A) Create two objects: box1 will be created using the default constructor; box2 will be
set using the other constructor (use width = 10.5”, length = 15.25”, and height = 12”).
B) Call the print method for each object to print the current dimensions for each. Print a
comment to identify which object you are printing at that time.
C) Use the “set” methods to set the dimensions for box1. Set the width to 24.25”, length =
35.506”, and height = 20.125”. Use the print method on this object again to print the new
dimensions to the output file.
D) Get the volume in cubic inches for each box and print them to the output file with
appropriate messages.
E) Get the volume in cubic feet for each box and print them to the output file with
appropriate messages.
F) Get the Surface area in square inches for each box and print them to the output file
with appropriate messages.
G) Get the Surface area in square feet for each box and print them to the output file with
appropriate messages.
H) I have two boxes of Christmas presents I need to wrap. They have the dimensions of
the box1 and box2. How many square feet of wrapping paper will I need to wrap these
boxes (don’t worry about edges!)? Print this figure to the output file with an appropriate
message.
I) I have two planters the same sizes as the boxes above. How many cubic feet of soil will
I need? Print this value to the output file with an appropriate message.
Download
Random flashcards
Arab people

15 Cards

Pastoralists

20 Cards

Nomads

17 Cards

Create flashcards