#include #include #include "CPstring.h" // file: stats2.cc; author: D. Ramm; date: 10/13/96 // file input; while with EOF to exit // Initialization from first data point // stats for undeterminded input int main() { int number, count = 0; int sum, max, min; string filename; ifstream filein; cout << "Enter file name: "; cin >> filename; filein.open(filename); if (filein >> number) { count = 1; sum = number; max = number; min = number; } while (filein >> number) { count++; sum += number; if (number > max) max = number; if (number < min) min = number; } if (count == 0) cout << "No data found in file " << filename << endl; else cout << "For " << count << " numbers read, Max = " << max << ", Min = " << min << ", Mean = " << 1.0*sum/count << endl; return 0; } Sample output: stats2 Enter file name: testdata For 6 numbers read, Max = 45, Min = -21, Mean = 8.83333 cat testdata 23 45 -11 3 14 -21 stats2 Enter file name: emptydata No data found in file emptydata cat emptydata