CS 112b
Spring 2002
Ileana Streinu

Homework 3

Thursday Feb. 14, 2001
Due Wednesday 2/20/2000 by midnight


Outline

This homework combines what we learned this week: struct's, sorting and templates. In addition, you learn how to proceed from the verbose description in English of a problem to a program. Unlike Hw2, this time you must design all the components of your program. Your files should be named and submitted exactly as indicated below. Read the whole handout before proceeding.

The problem

You are working for a company which designs software for the current Olympiad (quite late in the game, I know.) You have been asked to write a program to keep track of race results (skiing, skating, you choose what. I'll just describe it as if they'd be all running.) The program is given the appropriate data about a race and must provide information about the winner, the runner-up, the last one to complete the race. It also must display a sorted list of the participants (the fastest first, the slowest last).

Input

The way the organizers have set the race up is as follows.

  1. At fixed times, they record the exact time on a sheet of paper. For example 9:15:34:90 (hours, minutes, seconds, hundredths of a second). We will refer to these times as the absolute time marks.

  2. At the time they write this absolute time down, the organizers also start a chronograph and begin letting the runners go. For each runner who leaves, they record the runner's T-shirt number, and the value of the chronograph. We refer to this second time as the relative start time. For example
    101 0:0:0:01
    102 0:0:0:17
    
    This 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.

  3. When the runners arrive near the finish line, usually in clusters, the organizers use the same process and write down an absolute time down, start a chronograph, and record the relative time of arrival of each runner.

What the organizers give you is a data file with the information formatted in a very precise way. The example below will give you an idea of the format used.

      4
      888 9  15 34 90
      101 0  0  0  01
      102 0  0  0  17
      888 9  16 00 01
      103 0  0  0  0
      888 9  16 13 03
      105 0  0  1  13
      999 12 30 34 01
      101 0  0  10 32
      103 0  0  11 00
      105 0  0  12 03
      999 12 32 33 03
      102 0  0  0  1
      0
The example above shows that 4 runners participated in the race. This number will always be the first one listed in the data file. We also see that the runners started in 3 groups, each specified by an absolute start time (lines starting with the number code 888), and arrived in two groups, one around 12:30:34, one around 12:32:33. The absolute time of arrival is marked by the number code 999 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. For simplicity, colons are ommitted from the data file, and the time is recorded as four integers separated by spaces. The last line contains just one entry - a zero - which should suffice to denote the end of the input data.

The computations

Basically, your program has to compute the amount of time each runner took to complete the race and store it internally in a meaningful way. Based on this, it will then output list of runners ordered by completion time (the fastest runner first, the slowest last), as well as the winner, runner-up and the last one to finish the race.

The program

The problem should be implemented as a main program calling the appropriate functions. It should keep track (internally) of only one race at a time and provide information to the user based on the chosen menu options.

The user interface is menu-based. The options for the user are:

  1. Exit the program
  2. Enter the data for a race
  3. Print the data, as it was entered, for the race
  4. Compute and print the total running times for the runners (not necessarily in sorted order)
  5. Print the computed results in sorted order
  6. Find the winner
  7. Find the runner-up
  8. Find the runner who finished last
A typical session would consist in entering the data, printing it to check that it was entered correctly, computing the running times, sorting and printing, then printing the winner, the runner-up and the last runner.

Internal data structures

You must use an array of records to store the race information. Each record contains the id of a runner and the time it took for completing the race.

Code reuse

For sorting, you must use Selection Sort (done in class), which you should have previously tested for correctness.

Format of the race data, input and output

It should be exactly as specified, and entered all at once (i.e. without any further prompts from the program).

The output should list each runner and its total running time on a separate line.

Testing

The internal (allocated) array used for this program should have a size of at least 25 elements, but the program should be tested on arrays of various sized (as entered by the user).


Levels of complexity

You can complete this program at various levels of complexity, which will be reflected in your final grade for this homework. I recommend that you attempt to do the lower levels first, then proceed to higher levels.

Reminder about the typescript

The typescript file should be named exactly like this, and should be concise and readable - in particular, it should NOT contain any junk from more or emacs executions. It should show just the compilation and execution of the program on appropriately chosen input data.


To submit

3 files, named exactly as specified: Submit using submit Hw3.
Ileana Streinu