Project 4

Introduction

In this project we are going to be working with dynamic allocation of memory and pointers. The basic idea is to read in data and store it in an array. Unlike last time where you had to reject data after the array was full, this time you will "grow" your array and store all the data.

Details

For this project we are going to be working with people running a race. We will have a struct to store the information and then an array to store the struct. When the data is loaded into the array, you will sort the runners by who finished first. After you've loaded the runners, there will be an "interface" that allows you to find runners in three ways: by name, by bib number or by finish place.

You will write your code in a function with the following signature:

void runRace( istream &in, ostream &out );

Input

The istream will, like last time, contain the name of the input file you are to read and store and then be followed by the commands. After you load the input data and store it in the array you should process all the commands that are in the input istream. A sample input file might look like this:

filename: input.txt
find-name McPherson
find-place 10
find-bib 341

Sample Files

Here are 3 sample files. The commands.txt would be opened in main and passed to your runRace function as the istream it reads. The input1.txt is the named file in the commands.txt file that your runRace opens and stores in memory. The results1.txt is the output from my program running the commands from commands.txt on the data in input1.txt

Input Data

For this project we are going to use another classic format for stored data, the CSV, or Comma Separated Variables. So that means each piece of the input will be separated with a comma. 4 sample lines are included here, but see the sample files for a complete file:

Wilson,John Paul,1001,M,1:37:41,1:32:41
Choudhuri,Yong,1002,M,1:08:53,1:03:53
Brown,Lukas,1003,F,1:59:42,1:54:42
Smith,Lukas,1004,M,1:36:30,1:31:30

The data is listed in this order:

This data is random and there will be strange things like the incorrect sex being given to a runner. I'm going to say their parents were very hip and simply didn't follow society's naming guidelines.

After you've read the data from the data file, you will them process the commands.

Commands

All the command will simply display their results on the ostreamr, e.g. out << "find-name " << ... Any command that finds the requested information will display the fields in this order:

find-name
This command will search the list of sorted runners and find all the runners that have the given last name. Note this command might have more than one runner who matches the last name. So you will find all of the runners with that last name. If a runner or runners are found with the given last name, then display their information like this:
find-name Lee
2   Lee, Sofia  1018    M   1:13:15 1:08:15
7   Lee, Ameilia    1009    M   1:24:50 1:19:50
19  Lee, Liam   1019    F   1:55:42 1:50:42

So this shows multiple people with last name Lee.

--OR--

If no runners are found with the given last name, then you issue the output:

Sorry, no runners with last name <last name> were found.
find-place
This will find the runner who finished the race in that place. This will be determined by the runner who is in the array location associated with that place. For example, the 3rd place finisher should be stored in index location 2.
find-place 73
73  Wilson, Harry   1005    F   1:45:53 1:40:53

--OR--

If no runners are found in the given place, then you issue the output:

Sorry, no runners with place <place> were found.
find-bib
This will search the list of runners and find the runner who is associated with the given bib number. In this case, each bib should only be associated with 1 runner.
find-bib 1006
6   Wilson, Anna    1006    M   1:27:35 1:22:35

--OR--

If no runners are found in the given bib number, then you issue the output:

Sorry, no runners with bib <bib number> were found.

Sorting

The basic algorithm for sorting is as follows:

For each runner in the array, let's call this runner A
    For each runner after the runner we are currently comparing, let's call this runner B
        if A is slower than B
            swap A and B in the array
    next B
next A

Requirements

  1. You may not use the STL, e.g. vector, other than string and the streams we use.
  2. The initial size of your array must be 10.
  3. When you "grow" your array you must double the size.
  4. You must use a struct to store the runner information.
  5. You need to use functions where appropriate, there are at least 3-5 places where functions can be used.
  6. You must put your void runRace( istream& in, ostream& out ); declaration in a file named runner.h
  7. You must store the times, i.e. clock time and chip time, as a single integer. Think of this as total seconds
  8. You need to do the same commenting as on the other projects, e.g. variables, functions, and other "tricky" places as needed.

Due

This is due Friday November 21 by 11:55PM. Yes that is the Friday before Thanksgiving break starts. Don't put it off.

Grading

Zip up your runner.h and implementation file(s) and turn them into Web-CAT.