// CSE1502 Spring 2009 Homework #5 - Matt Mahoney // // This program prompts the user to enter the name of a file // containing a list of 2 or more numbers separated by white space. // Then it prints the mean, median, range, standard deviation, // and the list sorted in ascending order. // If the file does not exist or contains less than 2 numbers, then // it prints an error message. #include #include #include #include #include #include using namespace std; int main() { // Open the input file string filename; cout << "Input file? "; cin >> filename; ifstream in(filename.c_str()); if (!in) { cout << "Error: " << filename << " not found\n"; exit(1); } // Read the list of numbers into a vector vector v; double x; while (in >> x) v.push_back(x); // Make sure the size is at least 2 int n = int(v.size()); if (n < 2) { cout << "Error: input must contain at least 2 numbers\n"; exit(1); } // Print the size cout << "There are " << n << " numbers\n"; // Sort the vector sort(v.begin(), v.end()); // Compute the mean double mean = 0; for (int i=0; i