UMBC CMSC 104 * CSEE | 104 | current 104

CMSC104, Fall 2006

Programming Project 4

Golf Statistics Keeper

Out: Monday, December 4, 2006
Due: Tuesday, December 12, 2006 before midnight


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 job is to write a program that will read in the golf scores of several players in a golf game. You will then display some statistics about the scores. You will generate an average score and list those players who scored below the average. You will also provide the functionality to show the winning score. The player with the lowest score is the winner.

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

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

   /* Fill array with golf scores */
   numberOfPlayers = FillGolfScoreList (scoreList);

   /* Print the golf scores */
   PrintGolfScoreList (scoreList, numberOfPlayers);

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

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

   /* Find and print the players who had scores below the average */
   ProcessBelowAverage (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/s/b/sbogar1/pub/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:

76
80
73
74
89
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 
79
88
94
92
83
82
0

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

Welcome to CMSC104's Golf Statistics Program!

The following scores were entered:

Player  1: 79
Player  2: 88
Player  3: 94
Player  4: 92
Player  5: 83
Player  6: 82

The winning score was 79.

The average score was: 86.333.

The following players played a below average game:

 Player #       Score
----------    ----------
    1             79
    5             83
    6             82


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_0401 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_0401 Proj4