Question: Write a program that reads a text file containing a set of test scores, calculates the average, median and mode. The file name must be
Write a program that reads a text file containing a set of test scores, calculates the average, median and mode. The file name must be entered by the user. Use the main function provided and implement all other functions.
getScores:
Ask the user for the file name and use it to open the file containing the scores. If the file opening was unsuccessful, ask the user to enter it again until you succeed or return zero to main.
Read all scores to a vector. You will need to pass the vector by reference to this function.
calcAverage:
Calculate the average by adding all scores and dividing by the number of scores.
calcMedian:
Calculate the median. This function should test whether the file has an even or odd number of scores. If there is an odd number of scores, the median is the score in middle, given that the scores are sorted. If there is an even number of scores, you need to average the two in the middle.
calcMode:
Determines the score that appears more often in the data set.
print:
The scores sorted from least to greatest
The average (rounded to one-decimal place), median(rounded to one-decimal place) and mode
Use a range-based for loop in this function
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
