INTRODUCTION TO
PROGRAMMING IN
C++
Kalamazoo
College
PROGRAMMING
PROJECT
5:
BALLOON
RACE
PROJECT
Due at the beginning of Lab 6
This programming project may be done individually or in groups of two.
Remember that you may not work with the same person on more than
two of the programming projects.
If you do work with a teammate, hand in one copy of your code with both
names on it.
It is okay to get help from
the TAs and/or the instructor if you get stuck,
but you should try to do it on your own first.
The programming project for Week 5 (due at the beginning of the Week 6
lab) is to complete the Balloon Race project started in Lab 5, according to the
specifications below.
Specifications
The Balloon Race Project started with the following rough specification:
- Each balloon is a different color.
- No aquarium; paint entire window blue to represent the sky.
- All balloons start at same starting point, somewhere in the
lower-left corner of the screen.
- Every balloon rises to a randomly chosen altitude. Then it moves
right towards the finish line. In each move it either rises
between 4 and 6 units (randomly chosen) or moves right between 3 and
5 units.
- The 1st balloon to cross the finish line wins. If more than one
balloon crosses in the same simulation step, there is a tie.
In class, we identified two classes that would be useful in addition to the
main function -- Balloon and Display -- and
identified the data and behavior for which each should be responsible.
As we developed this design, several new issues and requirements
arose.
- Each balloon should randomly choose a "target altitude" (within
some sensible range) that it should reach before moving right. It
should decide on its target altitude when it is constructed.
- You may choose whether the balloon needs to reach the target
altitude exactly, or whether it should rise at least as high
as the target altitude.
If you choose the former, the distance of the last move up should be
the lesser of the amount randomly chosen or the amount necessary to
achieve the target altitude.
If you choose the latter, your balloon should stop rising as soon as
it has reached an altitude at or above the target altitude.
- You may choose whether the main function or the balloon
is responsible for determining whether a balloon should be rising
or moving forward. If you choose the former, those two functions
should be public; if you choose the latter, they should be private
functions called by a public, more generic Move function.
News Flash: Modified Specifications
I have made a few small changes in the specification of the problem that will
make the project both easier to program and more interesting to run.
- We won't print winners, so don't need to keep track of the winners
(just need a boolean, not a vector; no names or ids).
- Have the balloon randomly choose its color and its target altitude.
- Have main keep track of the finish line -- just asks balloon for
its X coord to see whether it crossed the line or not.
- Design choice: is main responsible for asking balloon whether it's
at its target altitude and then telling balloon to rise or move
forward, or does mail just tell balloon to move & balloon consults its
own target altitude to decide whether to rise or move forward?
- We will no longer use units that correspond to the dimensions of
the balloon; instead we will deal with pixel units. This means that a
balloon should rise between 20 and 60 or move forward between 45 and
100.
The Assignment
In the Lab Entrance Assignment and Lab for Week 5 you
started to implement your main function and the Balloon and
Display classes. The assignment for this programming project is to
finish implementing the Balloon Race Program.
Print and save your modifications.
- Print your 5 files: the main function and the header and
implementation files for Balloon and Display.
Remove the object code from the project, and
copy your Balloon Race folder
from the Temp folder to your floppy disk. You should then remove the
folder from the Temp folder on the C: drive.
- Turn in your project at the beginning of Lab 6.