CS 117, Fall 1999
Assignment 3: Data Processing, due gradually
You may work with a partner for this assignment. No groups of
three or more, please.
When you are done with each phase of this assignment, please submit your
code using the
Homework Submission Program.
The Goal
In this multi-stage project, you will develop a program that does
the following:
- Asks the user for an input file name and two output file names.
- Reads lines of the form "Name score score score score...score"
from the input file and stores them in appropriate variables.
(The scores on these lines might represent test scores or bowling
scores or white blood cell counts--for our purposes it won't matter.
What will matter is that the scores will all be integers, and that
each line will have one name and 10 scores.)
- Sorts the data alphabetically by name, and writes
lines of the form "Name average" to the first output file.
- Sorts the lines in decreasing order of average scores, and
writes lines of the form "Name average" to the second output file.
- Prints a summary of the data to the screen: the
number of lines of input, the overall mean of all the scores,
and the mean and maximum score for each of the 10
tests/bowling games/blood tests.
For example, suppose the input file contains
Norma 6 12 8 9
Stu 5 5 5 5
Abby 3 9 6 4
(simplified to four scores per line for this example).
Then the first output file will contain
Abby 5.5
Norma 8.75
Stu 5
and the second output file will contain
Norma 8.75
Abby 5.5
Stu 5.
Finally, the summary printed to the screen will say
something like
Number of people: 3
Mean score: 6.42
Test #1: mean 4.67, maximum 6
Test #2: mean 8.67, maximum 12
Test #3: mean 6.33, maximum 8
Test #4: mean 6, maximum 9
You will develop this program in relatively small steps, handing
in your code after each step.
Stage 1 : due 8:30AM Monday, 10/25/99
Write a program that:
- Asks the user for the name of an input file and an output file.
The input file will consist of a list of no more than 100 names, one per line.
Each name will consist of letters only, with no spaces or punctuation.
- Reads the names into an array of string variables.
- Sorts the names.
- Writes the names in sorted order, one per line, to the output file.
Stage 1.5: due never
Write a program that does the same thing as the Stage 1 program,
but instead of reading the names into an array of string variables,
read the names into the "name" fields of an array of structs defined like
this:
const int scoresPerPerson = 10;
struct Person
{
string name;
int score[scoresPerPerson];
};
Then, instead of sorting an array of string variables, you're
sorting an array of Person variables. Otherwise, everything stays
the same as in Stage 1.
Stage 2: due 8:30AM Friday, 10/28/99
The input file will now contain lines consisting of a name
followed by ten scores. Write a program that
- Asks the user for an input file name and an output file name.
- Reads the data into an array of structs as shown in
Stage 1.5 above.
- Sorts the array alphabetically by name.
- Writes the names and average scores to the output file.
Stage 2.5: due never
Add a second output file and sorting by average score to the
Stage 2 program.
Stage 3: due 5:00PM Monday, 11/1/99
The final program, including the second output file and the
on-screen summary, as described above.
Some unsolicited advice
Make a plan in prose or pseudo-code on paper before you start coding.
When you start coding, write the code on paper before going to the
machine.
Plan a sequence of smaller programs building up to each stage's
final version. For example, for Stage 1, you could (1) get the program
to read the names from the file and print them directly to the screen,
unsorted, (2) get it to store the names in an array, and then print
them to the screen, unsorted, (3) get it to store the names in
an array, and then write them to the output file, unsorted, and
finally, (4) get it to do the full Stage 1.
Every time you get a program that does what it does correctly, save
a copy of it and don't touch the copy any more.
Delete executables so you don't get nasty automatic e-mail telling
you you're over quota.
If you're stuck, don't suffer too long in silence. Talk to me or
Robin Smogor or a lab assistant or a friend.
Start early, keep in touch, and have fun.
Jeff Ondich,
Department of Mathematics and Computer Science,
Carleton College, Northfield, MN
55057
(507) 646-4364,
jondich@carleton.edu