/*--------------------------------------------------------------------*/ /* Problem chapter7_7 */ /* */ /* This program computes the average power of a specified columns */ /*--------------------------------------------------------------------*/ #include #include #include using namespace std; const int NCOLS = 7; const int NROWS = 10; double col_ave (double x[][NCOLS], int col); int main( ) { /* Define variables. */ double ave, power[NROWS][NCOLS]; int col; string filename; ifstream fin; /* Open input file. */ cout << "Enter the name of the input file: "<> filename; fin.open(filename.c_str() ); if(fin.fail()) { cerr << "error opening file " << filename << endl; return 0; } /* Read data. */ for (int i=0; i> power[i][j]; } /* reference the function to compute the column average. */ cout << "Which column do you want the average? " <> col; ave = col_ave(power, col); cout << "The column " << col << " has average value: " << ave << endl; return 0; } /* This function computes the average of the col column */ double col_ave(double x[][NCOLS], int col) { double sum = 0.0, ave; for (int i=0; i < NROWS; i++) { sum = sum + x[i][col]; } ave = sum / NROWS; return ave; }