Question: Instead of reading an array and taking an average / total based off the rows I need to change my code so that it reads

Instead of reading an array and taking an average / total based off the rows I need to change my code so that it reads from the columns.

I have already replaced some names inside my private header file and .cpp ex. from averageRow to averageCol.

void MatrixCalc::calculateTotalAverage() { for (int i = 0; i < 4; i++) { totalCol[i] = 0; // set running total initial value of each row to zero } // need nested looping... for (int i = 0; i < 4; i++) // i tracks row number { for (int j = 0; j < 5; j++) // j tracks column { totalCol[i] = totalCol[i] + myArray[i][j]; // running total for each row } averageCol[i] = static_cast(totalCol[i]) / 5;

} // Requirement number 4: grand total and grand average: for (int i = 0; i < 4; i++) { grandTotal = grandTotal + totalCol[i]; } grandAverage = static_cast(grandTotal) / 20;

// QA to check totalRow[4] and averageRow[4] cout << endl; for (int i = 0; i < 4; i++) { cout << "total and average for row " << i << " : " << totalCol[i] << ", " << averageCol[i] << endl; } cout << "Grand Total and Grand Average for Matrix: " << grandTotal << ", " << grandAverage << endl;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!