/******************************************************************************\ * * * Assignment 1 - Statistical Analysis of Text File * * * * flamingspinach * * * * Started: 2006-10-03 * * Finished: 2006-10-03 * * * * NOTE: See accompanying note for information on the algorithm * * http://www.mathbin.net/908 * * * \******************************************************************************/ #include #include #include using namespace std; int main () { ifstream in ("data.txt"); int i = 0, ranges [11] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; double x, max = 0, min = 11, sum = 0, sum2 = 0; for (;;) { if (in >> x) ++i; else break; sum += x; sum2 += x * x; if (x < min) min = x; if (x > max) max = x; ++ranges[(int)x]; } sum2 -= sum * sum / i; cout << setprecision(15); cout << "Mean of the values is: " << sum / i << endl << "Variance of the values is: " << sum2 / i << endl << "Maximum of the values is: " << max << endl << "Minimum of the values is: " << min << endl << endl; for (int c = 0; c < 11; ++c) cout << "Number of values in interval [" << setw(2) << c << ", " << setw(2) << (c+1) << "): " << ranges[c] << endl; cout << endl; system("pause"); return 0; }