/*--------------------------------------------------------------------*/ /* Problem chapter7_7 */ /* */ /* This program computes the average power of a specified row */ /*--------------------------------------------------------------------*/ #include #include #include using namespace std; const int NCOLS = 7; const int NROWS = 10; double row_ave (double x[][NCOLS], int row); int main( ) { /* Define variables. */ double ave, power[NROWS][NCOLS]; int row; 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 row average. */ cout << "Which row do you want the average? " <> row; ave = row_ave(power, row); cout << "The row " << row << " has average value: " << ave << endl; return 0; } /* This function computes the average of the row */ double row_ave(double x[][NCOLS], int row) { double sum = 0.0, ave; for (int j=0; j < NCOLS; j++) { sum = sum + x[row][j]; } ave = sum / NCOLS; return ave; }