Introduction to Programming (22C:16, 22C:106)
Homework 4: Due Thursday, 2/27/97
Problem 1: [5 points]
Solve Problem 3.8 from Section 3.7 (page 110).
Problem 2: [15 points]
This problem requires that you examine both the interface and the implementation
of the balloon class.
You will find the interface defined in the file balloon.h and the
implementation defined in the file balloon.cc.
Both of these files are available in the 22C16 courses folder on the
file server NEBULA MACAPPS.
-
Read the implementation of the function Burn() and
defined in the balloon class.
Explain briefly (and precisely) what of the function Burn() does.
The statement
myAltitude += ALT_CHANGE;
that you see in this function is simply a short-form for
myAltitude = myAltitude + ALT_CHANGE;
-
Now modify the implementation of the function Burn() so that
if the balloon is at height less than or equal to 50 meters,
then a burn increases its height by 10 meters; otherwise if the
current height of the balloon is more than 50 meters, then a burn
increases the height of the balloon by 15 meters.
The idea here is that as the height of the balloon increases, it is
easier for the balloon to ascend via burns.
Now run the program fly.cc (Program 3.6) twice: once with the original
balloon class and once with the modified balloon class.
Attach your output showing the difference in the behavior of these two runs
of the program.
-
Now start again with the original balloon class.
Get rid of the functions Ascend and Descend entirely from the
balloon class.
Then make the functions Burn() and Vent() public member functions.
Finally, rewrite the program fly.cc using calls to the functions
Vent() and Burn() (instead of to Ascend() and
Descend) so that the behavior of the program remains the same.
Sriram Pemmaraju
Wed Feb 19 17:41:28 CST 1997