Latest Revision: 11/24/2004
SIXTH CS 1500 SOLO PROGRAM: Grading Program
The purpose of this programming assignment is to get practice using files,
arrays, and for-loops.
Write a program that grades a multiple choice exam.
You must write the program with certain facts, assumptions, and
preconditions in mind:
Your program must correctly process the contents of testData,
whatever they turn out to be.
- The program gets all its input from a file named
- There is no way for you, the programmer, to know exactly what will be in
the file testData when the program executes.
- However we do know that the first line of testData is a
key like this one:
b b c b c d d c a d a d e c b e a d e b
The key will be like the one above, but not identical in
general. The key can be any string of 20 lower-case letters separated by
blanks. The key represents the set of answers to 20 multiple choice
- We also assume that the second line of testData is a single
non-negative integer -- call it numStudents -- which represents
the number of students who took the test.
- The final assumption is that there are 'numStudents more lines' in
testData following the second line. Each of those 'numStudents
lines' represents the 20 answers given on the test by one student.
- When the program runs, the contents of file testData could be
anything that conforms to the rules above.
Here are some very small examples:
a e c b b b a e a d e a a d e a c d b b
a e e a b c a b a b c c a a b e d d d d
b e a b c b e a e c d b b d d e c e b c
a e a b b b a b a d e a d d e a a d b b
In Example (i) above, we have a key and then the number '3'. This means that
the three lines that follow the '3' are the test answers of three students
(students #1, #2, and #3). For example, the fifth letter in the line after
the '3' is 'b'. That means that student #1 gave an answer of 'b' to the fifth
question on the test. (That answer of 'b' was correct, as we can verify by
noting that the fifth letter in the key is also a 'b'.)
d d e d b a d b c e e c b a a e a d b d
a a d e d b d a c b b a c a b d d e e c
a d a e d a d b a e e a b d c a b c c d
d b b a d c d b d c e d b e c b b d c d
e c b d c d d d a a d a b e d c b b a b
b e a e a e a d e a e b e a e d a c b c
e b e d b c a e b a b c c d d e c a a e
In Example (ii), we see that six students took the test.
After you turn your program in for grading, I will test it using some
versions of the testData file that I have never shown to you.
If your program works incorrectly on any of my versions of
testData, you will lose substantial credit.
You will need to use an editor to make versions of testData for
If you like, you may cut and paste sequences of letters from
I created this file of letters with a program that uses a "pseudo-random
number generator" -- a C++ library function named random.
OPENING THE INPUT FILE:
Your program will open testData with this statement:
ifstream infile("testData") ;
The program counts how many correct answers each person got. The program
prints a simple tabular report. Here is how the report must appear if example
(i) above is the contents of testData:
Student Number Number Correct PASS/FAIL
1 7 FAIL
2 6 FAIL
3 16 PASS
Of course, what will be seen in the report will depend on what is in
The column headings must be as shown. The spacing does not have
to be identical, but the report must be very tidy and readable.
The student numbers, from 1 to numStudents, must appear in the first
column. (Sorry, but it is not OK for the numbering to start at 0,
even though C++ arrays start at index zero. You must be careful to adjust
The next column must show the number of correct answers for each student.
The last column contains the word PASS or FAIL, depending on whether the
student got 60% or more correct.
THE DESIGN OF THE PROGRAM:
There must be at least three functions in the program (including
main). There must be at least two functions that have one or more
parameters. You may find you get a better design if you use more than three
I expect you to employ good principles of top-down design when you create your
program. Substantial credit will be withheld if you do not create a program
that uses functions appropriately.
There is a simplified functional diagram you could use for the design of your
There are no return-types or parameters shown in the diagram. That's because
I don't want to give you that information. I want you to decide what
return-types and parameters your functions should have.
- Make sure that each function does one thing well.
- Don't use any global variables.
I also want you to get the experience of writing a program that uses an array.
Therefore I am requiring that your program use an array to store the
key. You may use more arrays if you wish.
Because I am going to test all the programs by compiling and running them on
different versions of the input file, I need everyone in the class to use
exactly the same name for the input file. Therefore,
please name your file testData and use the command:
ifstream infile("testData") ;
in your program.
To see some C++ code with similarities to the code you need to write, look
that reads and prints golf scores.
Note: Come to class to get more discussion of how to design the program.
FORM AND FORMATTING REQUIREMENTS:
Write appropriate function declaration comments for each of your functions.
These are comments placed under each function declaration to explain the
purpose of the function, and to explain what the function does. Read the
comments in the example programs in your book, and write similar comments for
At the beginning of your program file put a header comment like
/* PROGRAM: Test Grader */
Name: Gordon Goodguy
User Name: goodge
Course: CS 1500, Computer Programming I
Instructor: John Sarraille
Date: January 01, 1970
Of course, in place of "Gordon Goodguy," you must put your own full name. In
place of "goodge" put your user (login) name. In place of "January 01, 1970"
put the date that you finished the program. Note that the comment
delimiters /* and */ are important. They need to be placed correctly or you
will get compiler errors.
I want you to make at least three different versions of the file testData with
which to test your program:
In the last file - the large one - there will be several lines of letters
after the integer numStudents. Each of those lines represents the answers
that one student gave on the test. You must write that last file so that
- one in which numStudents = 0;
- one in which numStudents=1; and
- one in which numStudents is a number larger than five
When you do your testing, make sure that all the output of the program is
- at least one of the students has a score of 0 (100% wrong),
- one student has a score of 11 (55% right),
- one has a score of 12 (60% right),
- one has a score of 13 (65% right), and
- one has a score of 20 (100% right).
Here's a nice way of managing different versions of testData for testing:
Remember: I am requiring that you write the program so that it assumes that
the input is contained in a file named testData. If you employ the
strategy described above then you can test different versions of
testData without difficulty.
- Make a file in which numStudents = 0, and call it testData_0.
- Make a file in which numStudents = 1, and call it testData_1.
- Make a version of testData file in which numStudents is larger than five
and call it testData_L.
- When you want to run the program with testData_0 as the input,
just do the command
cp testData_0 testData first
(this causes testData to be a copy of testData_0) and then run the
- When you want to run the program with testData_1 as the input,
just copy testData_1 to testData with the command
cp testData_1 testData first.
- When you want to run the program with testData_L as the input,
just do the command
cp testData_L testData first.
WHAT TO TURN IN:
You will be sending me two e-mail messages. Please follow these rules:
Here is the list of things you have to turn in:
- Always send me e-mail as plain text in the main message body.
Never send me attachments.
- Always use the exact subject line I specify for each
message. (I often get hundreds of e-mail messages in a week. The
subject line allows me to find and sort messages.) You will lose a
significant number of points on the assignment if you use the wrong
- Be very careful when you send the e-mail. You may use the
instructions in your
Hello World! lab exercise
for guidance. Of course, you will need to make the obvious changes to
those directions -- you have to use the correct subject line and
- Always send yourself a copy of each e-mail message you send to me,
check immediately to see if you receive the message intact, and
check within a few minutes to see if you have received e-mail notifiying
you about an undeliverable message. You are
responsible for sending e-mail correctly.
Note that there are no spaces in the subject lines given. It is important
that you do not insert any spaces. My e-mail address is:
- At the start of class on the
place the following item on the "counter" in front of me:
- a hardcopy (printed listing) of your program (the C++
source code). Make sure all the code is properly
formatted and that it all shows on the paper.
- Before midnight on the the due
date send me the following by e-mail:
- A copy of the source code (C++ code) with subject line:
- a (filtered) script, with subject line
showing (at least) the results of running the program on the three
input files described above in the section entitled "TESTING"
WHEN IS THIS ASSIGNMENT DUE?
Look for the due date in
the class schedule.
(It's at the top level of the class directory.)