UMBC CMSC 104 * | CSEE | 104 | current 104 |
Programming Project 4
Golf Statistics Keeper
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:
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.datThis 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.
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:
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