/* ************************************************************* * * * Name: Anthony Larrain * Date: Spring 2002, csc311 * * * * DESCRIPTION: This program will compute the mean and * * and median for a set of temperatures. * * The temperatures will be read from the * * keyboard. The statistics will * * will be printed to the console. * * * ************************************************************* */ #include #include #include using namespace std; int main() { vector temperatures; // object creation double value,mean,median; double sum(0); cout << "Enter temperatures (cntl-z for EOF)" << endl; while(cin >> value){ temperatures.push_back(value); sum += value; // same as... sum = sum + value; } int size = temperatures.size(); sort(temperatures.begin(), temperatures.end()); if(temperatures.empty()){ cout << "NO ELEMENTS IN VECTOR" << endl; system("PAUSE"); exit(1); }else if((size % 2) != 0){ median = temperatures[size / 2]; }else{ median = (temperatures[size / 2] + temperatures[ (size/2) - 1 ]) / 2.0; } cout << "The mean is: \t" << (sum/size) << endl; cout << "The median is:\t" << median << endl; system("PAUSE"); return 0; }