Object Oriented Programming in C++ - Lab 4
In this lab you will write a program to calculate some
statistics about a long jump competition.
There are a number of events in track and field in which athletes
compete to see who can achieve the greatest distance: for example,
who can jump the farthest, who can jump the highest, who can throw a
javelin (a spear) or shot (a cannonball) the farthest. Athletes strive
to win the competition by achieving the greatest distance, and also try
to achieve a "personal best". A personal best is achieved whenever an
athlete achieves a distance that is greater than they have ever
managed before.
In this program we will have an array of Athlete objects. Each Athlete
object will contain the information about a single athlete: their
name, their college, their personal best, and the distance they have
achieved in the current competition. Your program will read the data for
each athlete into the array, then find and print the winning athlete,
print any athletes that have achieved a personal best, and then print
out all the athletes.
Class Athlete should have the following data members:
- name (a string)
- college (a string)
- personal best (a Distance)
- distance in current competition (a Distance)
Class Athlete should have the following member functions:
- setAthlete: This function returns void and has four parms: name,
college, personal best, and distance in current competition.
- isBest: This function has no parms. It returns true if the
Athlete has achieved a personal best in this competition, and
changes the personal best data member to the new personal best.
If a personal best was not achieved, the function returns false.
- better: This function takes an Athlete as the parm.
It returns true if the invoking object went further in the current
competition than the parm; otherwise it returns false.
- print: This function returns void and has no parms. It prints
out all data members of the Athlete. When it prints the distances
it should print them as feet and inches, not yards, feet, and inches.
You will have to add one member function and modify one member
function in the Distance class:
- showInFeet: This function prints a Distance object using only
feet and inches. This function will not print a Distance in yards,
feet and inches. For each yard in the Distance the function will
increase the number of feet printed by 3. This function should not
change the yards and feet in the object. It only should change the way
they are printed. For example, if a Distance is 8 yards, 3 feet,
and 6.5 inches, showFeet will print the Distance as 27 feet 6.5 inches.
This is how distances are measured in athletic competitions.
- setDist: Modify this function so that the value of inches is
always less than 12 and the value of feet is always less than 3.
For example, if the parms passed to setDist are 0 yards, 10 feet,
17 inches, the values stored in the invoking object are 3 yards,
2 feet, and 5 inches.
Assumptions:
- To keep things from getting too complicated, you can assume there
is no tie - only one athlete has the longest distance.
- You will use the ISO C++ string class in this lab. To use the
string class, include the <string> header file.
- Make your array of Athlete objects big enough to hold 20 athletes.
- Read input from the keyboard and print output on the screen.
Your program must take input for each Athlete in the following form
(each of the following should be on a separate line):
name
college
distance in current competition (enter feet then inches)
personal best distance (enter feet then inches)
- After reading each Athlete, prompt the user to find out whether
he/she wants to enter another Athlete. If the user enters ‘y’ or
‘Y’, read another Athlete, otherwise stop reading.
- If you want an extra challenge, print out the second and
third place winners also.
Email Me |
Office Hours |
My Home Page |
Department Home |
MCC Home Page
© Copyright Emmi Schatz 2002