We wrote a program to calculate mean, variance and standard deviation of a set of numbers in our previous assignment. You should be able to use the code you already wrote for this exercise. We like to read a set of numbers from a file whose name is hard-coded in the program as a const variable, and calculate the mean, variance, and the median of the numbers. In order for the medina to work, we must sort the data. Your program must read the data file just ONCE, because we're using arrays. Your program will NOT have any input form the user.
Write the following functions as prototyped below. Do not alter the function signatures.
/// Computes the mean of an array containing n elements
/// @example mean(vals, 4) returns 3.5 if vals = { 2, 4, 3, 5}
double mean( const double values[], const uint n );
/// Computes the variance of an array containing n elements
/// @example variance(vals, 4) returns 1.666667
double variance( const double values[], const uint n );
/// Computes the median of an array containing n elements
/// @example median(vals, 4) returns 3.5
double median( const double values[], const uint n );
/// Sorts the elements of an array with n elements in ascending order
/// @example sortMe (vals, 4) changes the contents of vals
/// from {2, 4, 3, 5} to {2, 3, 4, 5}
void sortMe(double values[], const uint n );
Calculation of median of a set of numbers is pretty simple. For a sorted array of n elements, we calculate the median as follows:
If n is odd, the median is the middle number. The array element at n/2
If n is even, the median is the average of the 2 middle numbers. (array element at n/2-1 + array element at n/2) / 2
Median of 2, 3, 4, 5 would be: (3+4)/2 = 3.5
Median of 2, 3, 4, 5, 6 would be: 4
Write a client program to test your functions. You can create any data set to test your code, but your code must run with any data file. You can assume that there is no header line in the file and that the data can include any number (int or float).