Determine mean, median, mode, sample variance, sample standard deviation, minimum value, and maximum value.
Use at least six (6) programmer-defined functions; this excludes sort. At least three (3) must be void. Display unsorted array, sorted array, mean, median, minimum value, maximum value, mode (response frequency/histogram), sample variance and sample standard deviation. All output should be displayed in the main program with the exception of mode (response/frequency histogram).
User should be prompted for input file name. Only 40 values of sorted and unsorted arrays should be printed on one line. Please use a constant for size of array. ( const int SIZE=99)
For example, here's how I could open a file and loop through every space-delimited number in it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Example program
#include <iostream>
#include <string>
#include <fstream>
int main()
{
// test.txt might contain something like: 10 20 30 40 50 60
std::ifstream file("test.txt");
int my_int; // variable to store a number in
while (file >> my_int) // loop through every number in the file
{
std::cout << my_int << ", "; // print each number we find in the file
}
std::cout << std::endl;
}
You have to loop through each element in the array of elements, and the on each number, subtract the mean, and then square the result. Finally, divide by the number of elements.
Here's some code as a guide:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
double sample_variance(int arr[], int size)
{
double mean = average(arr, size); // you would make this function
double sum = 0.0;
for (int i = 0; i < size; i++)
{
int value = arr[i];
double shifted = value - mean;
double shifted_squared = shifted * shifted;
sum += shifted_squared;
}
double svar = sum / size;
return svar;
}