CSC112 Homework #3
A RACE...
Assume that the organizers of a race have asked you to write a program that will display the sorted list of the joggers, the fastest first, the slowest last.
The way the organizers have set the race up is as follows.
101 0:0:0:01 102 0:0:0:17This means that Runner 101 left one hundredths of a second after the absolute time mark of 9:15:34:90, and Runner 102 left 17 hundredths of a second after that same time mark of 9:15:34:90. In other words, Runner 101 left at 9:15:34:91, and Runner 2 at 9:15:35:07.
What the organizers give you is a text file with the information formatted in a very precise way. The example below will give you an idea of the format used.
4 start 9:15:34:90 101 0:0:0:01 102 0:0:0:17 start 9:16:00:01 103 0:0:0:0 start 9:16:13:03 105 0:0:1:13 finish 12:30:34:01 101 0:0:10:32 103 0:0:11:00 105 0:0:12:03 finish 12:32:33:03 102 0:0:0:1The example above shows that 4 runners participated in the race. This number will always be the first one listed in the file. We also see that the runners started in 3 groups, each specified by an absolute start time (lines starting with the keyword start), and arrived in two groups, one around 12:30:34, one around 12:32:33. The absolute time of arrival is marked by the keyword finish at the beginning of a line. Runner 102 arrived 1 hundredth of a second after 12:32:33:03, or at exactly 12:32:33:04.
Your assignment is to compute the amount of time each runner took to complete the race, and to output the list of runners ordered by completion time. The fastest runner first, the slowest last.
Implementation Details
Your class should also overload the <, <=, and + operators to allow you to compare time objects directly with the < or <= operators, and to add two time objects together (We'll see this in Wednesday or Friday's class).
typedef struct raceStruct; struct raceStruct { int number; timeClass rtime; };Then, an array of runners would make sense:
raceStruct Runner[somenumberthatyouwillhavetodefine];To initialize Runner 3 as having number 101, and an associated time of 9:10:11:12, for example, could be done as follows:
Runner[3].number = 101; Runner[3].rtime.init(9,10,11,12);
(Text added 9/29/99) Or, you might want to create a class for a runner, say runnerClass. This class would contain an integer representing the T-shirt number, and the four integers defining the time (hours, minutes, seconds and hundredths). This will result in a simpler approach than having a structure. Both ways are perfectly acceptable.
The next line will be an absolute start time, followed by 0 or more individual runners, each identified by a number and a relative start time, and each on a separate line.
There can be as many absolute start times as there are runners.
The race is long enough that the absolute finish times will always be listed after the absolute start times. There will be at least one absolute finish time. Each one will be followed by 0 or more runner entries. Each runner entry is a number (which will have been seen before) with a relative finish time.
Of course, the runners will finish in an order different from the order in which they left the start line.
4 101 0:0:0:01 102 0:0:10:17 103 0:1:2:0 105 0:0:3:13And make your program output the sorted list of the runners.
Then, when this works, improve the program so that it now reads a file of the form:
4 101 0:0:0:01 102 0:0:10:17 103 0:1:2:0 105 0:0:3:13 101 0:30:10:32 103 0:30:11:00 105 0:33:12:03 102 0:35:20:1where each time associated with a runner is an absolute time. Make the first time associated with a runner her start time, and the second time her finish time.
Then, when you can solve this problem, add the absolute start and finish time lines.
This way, learn how to progress through the assignment, one step at a time. This is the key to getting through programming projects easily.
Submission
Call your program race.cpp and submit it as follows:
% submit hw3 race.cpp