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
} // Requirement number 4: grand total and grand average: for (int i = 0; i < 4; i++) { grandTotal = grandTotal + totalCol[i]; } grandAverage = static_cast
// 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
Get step-by-step solutions from verified subject matter experts
