UMBC CMSC 104 CSEE | 104 | current 104

CMSC104, Spring 2006

Programming Project 4

Bowling Score Statistics Keeper

Out: Sunday, May 7, 2006
Due: Saturday, May 20, 2005 before 11:59 p.m.


The Objective

This project is designed to give you practice working with arrays and functions. It will also give you practice passing arrays to functions.

The Task

Your Saturday evening bowling league has asked you to write a piece of software to help them analyze bowling games. Your job is to write a program that will read in the bowling scores of several players in a game. You will then display some statistics about the scores. You will generate an average score and list those players who scored above the average. You will also provide the functionality to show the winning score.

The Details

Below is the main() function you must use in your program:
int main()
{
   int scoreList [MAX_PLAYERS]; /* Array to store bowling scores */
   int numberOfPlayers = 0;     /* Total number of scores entered */
   int averageScore = 0;        /* Average bowling score */
   int winningScore = 0;        /* The winning bowling score */

   printf("\nWelcome to CMSC104's Bowling Statistics Program!\n\n");

   /* Fill array with bowling scores */
   numberOfPlayers = FillBowlingScoreList (scoreList);

   /* Print the bowling scores */
   PrintBowlingScoreList (scoreList, numberOfPlayers);

   /* Find and print the winning score */
   winningScore = FindWinner (scoreList, numberOfPlayers);
   printf("The winning score was %d.\n\n", winningScore);

   /* Calculate and print the average bowling score */
   averageScore = CalculateAverageScore (scoreList, numberOfPlayers);
   printf("The average score was: %d.\n\n", averageScore);

   /* Find and print the players who had scores above the average */
   ProcessAboveAverage (scoreList, numberOfPlayers, averageScore);

   return 0;
}

You MUST use the main() function exactly as it is given. However, you need to add the following code before main:

You must also add the definitions of the functions after main(). You may add additional functions if you wish.

Input to the Program

A data file containing the items for you to use as input to your program will be provided. The items are all greater than 0. The last value in the file will be 0. This is the sentinel value that signals the program to stop reading items.

To use the data file as input to your program, you will use Linux redirection. By using redirection, you can tell Linux to read data from a file rather than from the keyboard. The scanf statement that you use in your program will look exactly the same as it would if you were getting your input from the keyboard. But since you will be getting the values from a file instead of from a user typing at the keyboard, you will not need to prompt the user. When you run your program, use the following command:

       a.out < scores.dat
This is how Linux redirection is done. It is saying to run your executable file using the file scores.dat as input.

You will need to copy the file scores.dat into your directory. To do this, go to the directory where you would like to store scores.dat. Then, use the following command to copy scores.dat into the directory:


    cp /afs/umbc.edu/users/d/b/dblock/pub/CS104/Proj4/scores.dat .

Notice that the space and period at the end of the command are part of the command.

Here is a example of what the input data file could look like:

211
198
234
179
207
118
186
0

You will also find proj4.c in the directory with scores.dat. You can copy it to your own directory following the above directions.

Sample Output

linux2[3]% gcc -ansi -Wall proj4.c
linux2[4]% cat scores.dat 
211
198
234
179
207
118
186
0

linux2[5]% a.out < scores.dat 

Welcome to CMSC104's Bowling Statistics Program!

The following scores were entered:

Player  1: 211
Player  2: 198
Player  3: 234
Player  4: 179
Player  5: 207
Player  6: 118
Player  7: 186

The winning score was 234.

The average score was 190.

The following players played an above average game:

 Player #       Score
----------    ----------
    1            211
    2            198
    3            234
    5            207

linux2[6]% 
Your output does not have to match the sample exactly, with a few exceptions:

Submitting the Program

Here is a sample submission command. Note that the project name starts with uppercase 'P'.

submit cs104 Proj4 proj4.c

To verify that your project was submitted, you can execute the following command at the Unix prompt. It will show the file that you submitted in a format similar to the Unix 'ls' command.

submitls cs104 Proj4