Question
In C++ This program will read a group of positive numbers from three files ( not all necessarily the same size), and then calculate the
In C++
This program will read a group of positive numbers from three files ( not all necessarily the same size), and then calculate the average and median values for each file. Each file should have at least 10 scores. The program will then print all the scores in the order that they were input, showing each number and what percentage it is above or below the average for each file. Note: Finding the average doesnt require an array. Finding the median and the percentages does require an array.
- The user should be prompted for the three file names which you should store in sring variables for file processing.
- The program will read values until the user encounters an EOF for that file to quit.
- The program must provide an error message for zero or other negative numbers.
- Do not presume that all the numbers will be integers..
- The program must provide reasonable prompts and error messages to the users.
- The programs output must be properly labelled.
- The program must handle the case of an empty array properly by producing a reasonable error message. It must not attempt to do any calculations on the empty array.
- The programs output does not need to be lined up perfectly.
- You must display the deviations from the average as positive numbers with some wording (e.g., 50.253% below and 25.22% above) rather than as a simple number (e.g., -50.253% and 25.22%) for each file with a heading for each file corresponding to the lable as given below..
- Finally It should have embedded in each file a lable for that file ( name of the scores) such as class A, class B , class C etc.
- Print out the lable for the file and the average for the file with the highest average and its value. Do the same for the file with the highest median, and f inally the file with the highest average of the percentage below the average for that file and its value.
Finding the Median
To find the median of a group of n numbers, sort them into order. If n is odd, the median is the middle entry. In an array named @data with elements starting at index zero, this will be element $data[(n-1)/2]. (Of course, you will have to put a scalar variable in place of n)
If n is even, the median is the average of the numbers surrounding the middle. For an array named @data with elements starting at index zero, this is ($data[(n/2)]+$data[(n/2)-1])/2.
Here is sample output from three separate runs of the program. User input in bold and italics.
Scores Report
Enter fie name for first file : class_A.txt
Enter fie name for first file : class_B.txt
Enter fie name for first file : class _C.txt
For class A The average is 8 The median value is 6 Value % above/below average 4 50% below 6 25% below 14 75% above For class B The average is 9 The median value is 10 Value % above/below average 3 50% below 6 25% below 12 75% above For class C The average is 7 The median value is 6 Value % above/below average 4 50% below 8 25% below 9 75% above File A had the highest average of 35.5 File B had the highest median of 34 File C had the highest average percent of the scores below the average with a value of 47.25.
In this example, the percentages all happened to come out to be integers. For an arbitrary set of numbers, this wont be the case. Do not truncate your results to integers use two decima places for values that our output.
Sorting an Array Numerically
When you sort an array, the default is to sort in alphabetical (ASCII/Unicode) order. This isnt what you want for an array containing numbers. Otherwise, the number "47" (as a string) will sort before the number "5" (as a string).
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started