Question: The name of the file must be stats.cpp. Write a program that implements the following statistical analysis functions as defined below. In your main ()
The name of the file must be stats.cpp.
Write a program that implements the following statistical analysis functions as defined below. In your main() function:
- Ask the user to enter the number of values to be processed
- Dynamically allocate an array of integers based on the users input
- Allow the user to enter the values and store them in the array
- Create a menu that enables the user to choose the statistical function
Based on the users choice one of these functions will be called and the result displayed:
a) getAverage(int *arr, int size): this function returns the average of the numbers in the array pointed to by arr. arr is a pointer to an array passed as an argument and size is the length of the array.
b) getMedian(int *arr, int size): this function returns the median. Make sure you enter sorted numbers to get a valid median value.
c) getLargest(int *arr, int size): this function returns the highest value in the array pointed to by arr.
d) getSecondLargest(int *arr, int size): this function returns the second largest value from the array pointed to by arr.
Coding requirements for submitted file:
- Validate all user inputs using loops
- Allow the user to choose when to end the program by adding something like Enter XX to Quit option to your menu
- Call a sorting function from getMedian function to be able to calculate the median
Sample run:
Enter number of values to be processed: 0
Invalid Input! Please enter a value >= 0: 5
Please enter the values: 4 7 42 30 19
Enter choice:
1. Average.
2. Median.
3. Largest.
4. Second Largest.
5. To Quit
1
The average is: 20.4
Enter choice:
1. Average.
2. Median.
3. Largest.
4. Second Largest.
5. To Quit
2
The median is: 19
Enter choice:
1. Average.
2. Median.
3. Largest.
4. Second Largest.
5. To Quit
8
Invalid Choice! Please enter your choice: 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
