CS 117 Assignment
Due Wednesday, 5/20/98
For this assignment you will write a data-processing program.
A legal input file for this program will consist of lines like
this:
Bernice 10 23 443 24
Zebediah 27 32 32 2
Agatha 2 41 16 5
Neville 32 222 1 3
Maybe they're miniature golf scores, maybe they're test scores,
maybe they're blood test results. Let the numbers
mean whatever you want them to mean.
Every person in the input file will have four scores.
You may assume that there will be no
more than 100 people in the data file.
Your task is to read this data file in, and print out a list
of names, maxima, and averages, sorted by
average score.
Thus, the output corresponding to the 4-person file example above
should look something like this:
Name Max Avg
--------------------------
Bernice 443 125.00
Neville 222 64.50
Zebediah 32 23.25
Agatha 41 16.00
Some advice
This program is big enough that you need to think carefully about
how to organize it, what the interfaces of your
functions should look like, and in what order you will implement
and test the routines.
You might, for example, decide to define
a class to represent a single person
class Person
{
private:
string mName;
int mScores[4];
etc.
};
and use an array of 100 Persons as your main data structure.
Then, you might make a plan of stages of the development of
your program:
- Stage 0: Write a data file with names and scores as
described above. You'll need such a file to test your programs.
- Stage 1: Ask the user for a file
name, open the file, read one line at a time from the file,
and print each line to the screen. Code it, debug it, and save a
copy.
- Stage 2: Ask the user for a file name, open the file,
read one line at a time from the file, and store the data from each
line in the appropriate Person class. When the file is all
done, loop through the array of stored Persons, printing out
names and scores to make sure you have successful read the data
into the array of Persons. Code it, debug it, and save a
copy.
- Stage 3: Do everything as in Stage 2, but print out
the names, averages, and maxima (not the scores). No sorting yet.
Code it, debug it, and save a copy.
- Stage 4: Do everything as in Stage 3, but sort by average
before printing. You're done.
You may certainly design a different plan, but you should plan some way
to develop and test your program gradually. Trying to code it
all in one blow and then debug and test the result is
a recipe for long frustrating sessions in the lab.
Start early, stay in touch, and have fun.
Jeff Ondich,
Department of Mathematics and Computer Science,
Carleton College, Northfield, MN
55057
(507) 646-4364,
jondich@carleton.edu