ESc 014

Assignment 6 -- The Duck Race Revisited
Due Tuesday, May 21, 2002

Objectives

Introduction

Remember the Duck Race assignment from ESc 013? It involved Union's traditional senior class fundraiser. People contribute a small amount a money to sponsor an artificial duck. The ducks are then raced in a stream flowing through Jackson's Gardens.

Last term, you were asked to produce two reports about who sponsored which duck, and the order in which the ducks finished. You'll be redoing those two reports here, but using the more advanced C++ concepts you've learned up to now. This will make your program more efficient and better able to handle more generalized input.

Your Mission

Download the input file ("duckrace.txt") from BlackBoard. Each line of this file contains a person's name, the number of the duck s/he sponsored, and the place that the duck finished in the race. For example, part of the input file may look like this:
Jimmy Carter 11 6
Prince 3 8
Samuel L Jackson 5 2

This means that Jimmy Carter sponsored duck #11 that finished in sixth place, while Samuel L Jackson's duck #5 came in second. Note that the names of the sponsors could take one of three forms:

Your job is to write two reports to two separate output files. Both are tables of sponsors, duck numbers, and duck finishing places, similar to what you see below. The first report is sorted by duck number and lists the sponsor's last name only (or first name in the case of only a single name). The second report is sorted by duck finishing place and lists the sponsor's full name.

Report 1 - Duck Order

Duck #

Name

Place

3

Prince

8

5

Jackson

2

11

Carter

6

...

Report 2 - Place Order

Place

Name

Duck #

2

Samuel L Jackson

5

6

Jimmy Carter

11

8

Prince

3

...

The Details

You are to use a single array of structs to hold the data. You may assume that the array will hold no more than 50 sponsors. Each struct will have the following components:

The algorithm for your program (that is, the step-by-step process of what you need to do) follows:

  1. Initialize the array of structs. Set int variables to zero, character variables to a space, and string variables to the empty string ("" -- that's two double quotes with nothing in between).
  2. Read the input from the file into the array. You are required to use the get command to read the file in character by character.
  3. Use an in-place sort routine (SelectionSort is fine) for sorting the structs in the array by duck number.
  4. Write out the first report. Since the array is now sorted by duck number, you just need to write out the array items in order.
  5. Resort the array (in-place) by duck finishing place.
  6. Write out the second report.
You are required to use the following functions: As always, you are encouraged to use other functions too, but the ones above are required.

The Hard Part

The most maddening part of this assignment will be parsing the input file in the correct way in the createArray function. Write the function down in English first. You may want to create other "helper" functions such as getFirstName or getLastName that break the task down even further. Use the character functions in the <cctype> library (p. 356) to check for different cases. Test as you go.

Grading

50 points will be divided as follows:

As always, paste in your test results at the bottom of your source code and turn in a hard copy of this assignment along with an electronic copy on BlackBoard.

Administrative statement

This is an individual project. I encourage you to talk to others about the general nature of the project and ideas about how to pursue it. However, the technical work, the writing, and the inspiration behind these must be substantially your own. If any person besides you contributes in any way to the project, you must credit their work in your report. Similarly, if you include information that you have gleaned from other published sources, you must cite them as references. Looking at, and/or copying, other people's programs or written work is inappropriate, and will be considered cheating.


Return to Assignment Index