// 22.5HV2 Software Engineering II // Unit 1 Exercise 1 #include #include #include void func(float [], int n, float&, float&, float&); int main(int argc, char *argv[]) { ifstream ins; float array[100], min, max, average; int i=0, num; if ( argc!=2 ) { cerr << "USAGE: ex1 infile" << endl; return 1; } ins.open(argv[1]); if ( ins.fail() ) { cerr << "Error opening " << argv[1] << endl; return 1; } ins >> array[i]; while ( !ins.eof() ) { // test for end of file i++; ins >> array[i]; } num = i; ins.close(); if ( num>0 ) { // Must check for empty file func(array,num,min,max,average); cout << "Minimum value = " << min << endl; cout << "Maximum value = " << max << endl; cout << setprecision(3); cout << "Average value = " << average << endl; } else cout << "Empty file!" << endl; return 0; } void func(float array[], int n, float &min, float &max, float &avg) { int i; float sum = 0.0; sum = min = max = array[0]; for (i=1;i max ) max = array[i]; } avg = sum/n; }