You will be writing a program to read student scores from the keyboard, save them in an array, and compute some basic statistics about the scores. Your program must
- Prompt the user to enter student scores
- Compute the maximum, minimum, and average scores
- Display the score statistics to the screen
Here is an example compilation and execution of the program:
linux3% g++ -Wall -ansi lab2.cpp -o lab2 linux3% ./lab2 Enter a score (-1 when done): 80 Enter a score (-1 when done): 72 Enter a score (-1 when done): 64 Enter a score (-1 when done): 91 Enter a score (-1 when done): 97 Enter a score (-1 when done): -1 Max score is 97 Min score is 64 Average is 80.8
To get you started, a template of the program is provided below. You can copy and paste the template into a text editor such as Emacs. Alternatively, you may copy the file to your working directory from Prof. Marron's public folder on GL:
cp /afs/umbc.edu/users/c/m/cmarron/pub/cmsc202/lab2.cpp .
To complete the program, you must:
- Add code to prompt the user and read scores from the keyboard; the user should enter a negative value when done entering scores.
- Write a min() function to compute the minimum value in an integer array.
- Write an average() function to compute the average value of an integer array. Remember that the average is a floating point number, and so you must ensure that floating-point division is used in the computation of the average.
- Add calls to the min() and average() functions in main().