SOURCE FILE: batStats.cpp.shell
/* This is a "shell" of a solution to the batting statistics
programming assignment. If you wish, you may use it. If you
wish, you may fill it out and then submit it as your solution
to the programming problem. */
/* ############################################################ */
/* Program BatStats */
/* ############################################################ */
/*
This program reads batting statistics from a file called
"teamData" and outputs a table of batting averages and total
walks. See the program assignment for more information.
*/
#include <fstream.h>
#include <iomanip.h>
#define NUM_PLAYERS 25
#define FIRST_PLAYER 0
#define LAST_PLAYER 24
void InitLists (int hitsIL[], int walksIL[], int outsIL[]) ;
void GetData (int hitsGD[], int walksGD[], int outsGD[]) ;
void MakeHeading() ;
void MakeReport (int hitsMR[], int walksMR[], int outsMR[]) ;
int main ()
{
/* This main program is complete. It doesn't need any
changes. */
int hits[NUM_PLAYERS], walks[NUM_PLAYERS], outs[NUM_PLAYERS] ;
InitLists (hits, walks, outs) ;
GetData (hits, walks, outs) ;
MakeHeading() ;
MakeReport (hits, walks, outs) ;
}
/* ############################################################ */
/* InitLists */
/* ############################################################ */
/* InitLists initializes all the array values to zero */
void InitLists (int hitsIL[], int walksIL[], int outsIL[])
{
for (int i=FIRST_PLAYER; i<=LAST_PLAYER; i++)
{
/* fill this in */
}
}
/* ############################################################ */
/* GetData */
/* ############################################################ */
/*
GetData reads information about baseball players from file
"teamData." File teamData is a series of records like this
one:
15 3 2 8
Each record consists of a player number, number of hits,
number of walks, and number of outs (in that order). The
record represents the performance of one player in one game.
GetData reads all the records.
For each player number N, GetData adds all the hits for player
N that are recorded in file teamData. GetData leaves the
total of these hits in array slot hitsArray[N]. Similarly,
GetData puts total walks and outs of player N in walksArray[N]
and outsArray[N].
As an example, after processing the data below
15 3 2 8
4 2 3 7
15 4 1 4
hitsArray[15] would be 7, hitsArray[4] would be 2. The other
values would be:
index walksArray outsArray
4 3 7
15 3 12
*/
void GetData (int hitsArray[], int walksArray[], int outsArray[])
{
int playerNum, next_hits, next_walks, next_outs ;
ifstream dataFile ("teamData") ;
while (dataFile >> playerNum)
{
/* put code here that reads the rest of the numbers on
the current line into the variables next_hits,
next_walks, and next_outs. (in that order). */
/* put code here that adds next_hits to
hitsArray[playerNum], adds next_walks to
walksArray[playerNum], and adds next_outs to
outsArray[playerNum]. */
}
}
/* ############################################################ */
/* MakeHeading */
/* ############################################################ */
/*
MakeHeading writes out a table heading that looks like this:
Batting Statistics
Player # Batting Av Walks
*/
void MakeHeading()
{
/* fill this in. */
}
/* ############################################################ */
/* MakeReport */
/* ############################################################ */
/*
MakeReport prints out the report that goes under the heading
made by MakeHeading. It is a three column report. The
player numbers appear in the first column (in ascending
order). In the second column the batting average of the
respective player appears. In the third column the total
number of walks of the respective player is written. The
formatting of the numbers is as specified in the assignment
page.
*/
void MakeReport (int hitsMR[], int walksMR[], int outsMR[])
{
/* fill this in. */
}
/* ############################################################ */