#include #include #include #include using namespace std; /**************************************************** main() reads in numbers from a file, then compute the min, max, average, and std deviation. ******************************************************/ int* readArrayFromFile(string filename, int &N); void calcMinAndMax(int *array, int N, int &min, int &max); double calcAverage (int *array, int N); double calcStddev (int *array, int N, double average); int main() { // Read the array int N; int* array = readArrayFromFile("numbers.txt", N); cout << "Got array of size: " << N << endl; // Get the min and max int min, max; calcMinAndMax(array, N, min, max); cout << "Min is " << min << endl; cout << "Max is " << max << endl; // Compute the average double average; average = calcAverage(array, N); cout << "Average is " << average << endl; // Compute standard deviation cout << "Std. deviation is " << calcStddev(array, N, average) << endl; return 0; } // function readArrayFromFile() // Reads from a file that looks like this // N = 3 // DATA: // 67 // 61 // 82 int* readArrayFromFile(string filename, int &N) { ifstream fin(filename.c_str()); // Get header info string junk; fin >> junk >> junk >> N >> junk; // Make the array int *array = new int[N]; // Read data in for (int i=0; i> array[i]; } return array; } // Calculate min and max value of array void calcMinAndMax(int *array, int N, int &min, int &max) { // defaults min = array[0]; max = array[0]; // check whole array for (int i=0; i max) { max = val; } } } double calcAverage (int *array, int N) { int sum = 0; for (int i=0; i