(Latest Revision: 05/06/2000)
SIXTH CS 1500 SOLO PROGRAM: Batting Statistics
OBJECTIVE:
The purpose of this programming assignment is to get
practice using files and arrays with for-loops.
THE ASSIGNMENT:
Your assignment is to write a program that computes batting
averages.
INPUT:
The program opens an input file with the statement:
ifstream infile("teamData") ;
The file called teamData consists of a series of zero
or more game records like this one:
15 3 1 6
There is one record per line. The meaning of the record above
is that in one particular game played by our team, player
number 15 got 3 hits, 1 walk, and 6 outs. For each player,
there can be zero or more records in the file. The idea is
that the file may contain information on more than one game,
and a given player may or may not have gotten a chance to bat
in any particular game. The player number can be any number in
the range 0..24 (including 0 and 24).
Here is a very small example of the kind of input that one
could see in a teamData file.
3 1 2 3
12 2 0 4
7 1 1 3
8 2 2 4
24 4 2 1
9 2 1 6
1 3 0 9
7 4 1 1
20 6 3 23
OUTPUT:
The program computes a total number of hits, walks, and outs
for each player.
These totals are computed as sums taken over all the
records corresponding to the player. For example, for player
number 7 in the sample above, the total number of hits is
5=1+4, the total number of walks is 2=1+1, and the total number
of outs is 4=3+1.
The program also computes the batting average of each player
using the following formula:
batting_average = 1000 * total_hits / (total_hits + total_outs)
The number of walks is not used in the formula for computing
the batting average.
The program prints a tabular report on all the players, like
this sample:
Batting Statistics
Player # Batting Av Walks
0 0 0
1 250 0
2 0 0
3 250 2
4 0 0
5 0 0
6 0 0
7 556 2
8 333 2
9 250 1
10 0 0
11 0 0
12 333 0
13 0 0
14 0 0
15 0 0
16 0 0
17 0 0
18 0 0
19 0 0
20 207 3
21 0 0
22 0 0
23 0 0
24 800 2
As you can tell from the sample,
- The report above corresponds to the sample input given
above.
- The batting average is expressed as an integer between 0
and 1000. It should not contain a decimal point.
- a player with no hits or outs is assigned a batting
average of zero.
THE DESIGN OF THE PROGRAM:
There must be at least two functions besides main in
the program, each having one or more parameters. You may find
it convenient to use more than two functions.
You must create your own design of this program. I am
expecting you to employ good principles of top-down design.
Substantial credit will be withheld if you do not create a
program that uses functions appropriately.
You must use arrays. Probably you will find that using three
arrays works well. The arrays can be named hits,
walks, and outs, and they can all be indexed
from 0 to 24, for the 25 players.
The table that your program prints out must have a nice neat
heading. The heading must include a centered title of the
table, and centered titles of the columns of the table.
Pretend that you are doing this for your boss at work, and do a
nice job.
Because I am going to test your program by running it, I need
everyone in the class to use exactly the same name for the
input file. Therefore, please remember to use the command:
ifstream infile("teamData") ;
in your program.
To see some C++ code with similarities to the code you need to
write, look at the
sample program
that reads and prints golf scores. Also check out
the sample input
and
corresponding output
for the golf scores problem.
FORM AND FORMATTING REQUIREMENTS:
Write appropriate header comments for each of your functions.
Header comments are the comments that appear at the beginning
of the function, telling what it's purpose is and what the
preconditions and postconditions are, and so forth. You may
pattern your header comments after the example code in your text
book, or you may use
this information
as your guide.
At the beginning of your program file put a header comment like
this:
/* PROGRAM Flooring Maker */
/*
Name: Gordon Goodguy
User Name: goodge
Course: CS 1500, Computer Programming I
Instructor: John Sarraille
Date: November 31, 2001
*/
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 "November 31, 2001" 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.
WHAT TO TURN IN:
Before midnight on the due date, e-mail the following two items
to me:
- A copy of the source code, properly documented.
- A filtered script showing an appropriate number of
test runs with different kinds of input.
My e-mail address is:
john@ishi.csustan.edu
Please use the following subject lines exactly
for the e-mails:
For the source file: CS1500_Solo6_Source
and for the script file: CS1500_Solo6_Script.
Note that there are no spaces in these subject lines. If you
like, you can copy and paste the subject lines right from this
document.
Thanks! Your use of these subject lines will
really be a big help to me when I try to sort through the
perhaps hundred e-mail messages that will be in my electronic
mailbox!
WHEN IS THIS ASSIGNMENT DUE?
Look for the due date in
the class schedule.
(It's at the top level of the class directory.)