In this assignment you will practice using searching and sorting techniques to extend the functionality of your previous homework that calculated statistics on a series of integers. This assignment has been adapted from programming exercises 12.5, 12.6 and 12.11 from our textbook The Art and Science of C. You should work on your own for this assignment.
The median is the data value that occupies the center position in a list whose values have been sorted from lowest to highest. If the list contains an even number of values and therefore has no center element, then the standard convention is to average the two values that fall closest to the midpoint.
The mode is the data value in a list that appears most frequently. If there are several values that occur equally often and outnumber any of the other values, you may simply return any one of these values as the mode.
In order to calculate both the median and the mode it is helpful to first sort the list of numbers. Our program will perform this step before it begins doing any of the statistical measures.
In the following sample run, the length of the list is 5, which is odd, so there is a single center element to use as the median, which in this case is 7. Notice that here we have two modes because both 5 and 20 appear twice in the list. My program always reports the first one it finds when the list is in sorted order, but your program need not work this way.
This program will analyze a list of integers by calculating the mean, median, mode and standard deviation. Enter integers to be stored, -1 to end. ? 20 ? 20 ? 5 ? 7 ? 5 ? -1 Sorted values 0: 5 1: 5 2: 7 3: 20 4: 20 Mean: 11.4 Median: 7 Mode: 5 Std Dev: 7.05975
In the next sample run, the length of the list is 10, which is even, so there is no single center element to use as the median. The two center elements are 40 and 45 and their average is 42.5. There is only one mode for this list. It is the value 10 which appears 3 times.
This program will analyze a list of integers by calculating the mean, median, mode and standard deviation. Enter integers to be stored, -1 to end. ? 10 ? 100 ? 10 ? 75 ? 60 ? 75 ? 10 ? 35 ? 45 ? 40 ? -1 Sorted values 0: 10 1: 10 2: 10 3: 35 4: 40 5: 45 6: 60 7: 75 8: 75 9: 100 Mean: 46 Median: 42.5 Mode: 10 Std Dev: 29.7321
cp originalFileName newFileName
double Median(int array[], int n);
int Mode(int array[], int n);The solution to this problem is not as straight forward as the solution to finding the median. Work through some examples on paper, and then try to come up with a pseudocode algorithm before starting to implement your answer. Because the array is sorted, you should only need to traverse the array one time in order to find the mode.
Use cs21handin to turn in your program.