2D_arrays_complete

# 2D_arrays_complete - Page 2 for(row = 0 rowSum = 0 r...

This preview shows pages 1–4. Sign up to view the full content.

Sheet1 Page 1 // CMPSC 101 Class #14 Demo #1a #include <iostream> #include <fstream> using namespace std int main() { int row = 0 int col = 0 int sum = 0 int scores[5][3] = {0} int rowSum = 0 int colSum = 0 double teamAve = 0.0 double colAverages[3] = {0} ifstream infile("C:/Temp/scores.txt") // ****** computing team average ****************** for (row = 0 { for (col = 0 { //cout << "Bowler #" << row + 1 << ", what is the score to game #" << col + 1 << ' ' infile >> scores[row][col] sum = sum + scores[row][col] } } teamAve = double (sum) / 15 cout << "The team average is " << teamAve << endl // ******* neatly displaying the 2D array ********************* for (row = 0 { cout << "Bowler #" << row + 1 << "'s scores\t" for (col = 0 { cout << scores[row][col] << "\t" } cout << endl } // ****** computing row averages **************

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Sheet1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Page 2 for (row = 0 { rowSum = 0 r for (col = 0 { rowSum = rowSum + scores[row][col] } cout << "The total of the scores in row " << row + 1 << " is " << rowSum << endl cout << "The average of this row is " << rowSum / 3.0 << endl } // ****** computing column averages ***************** for (col = 0 { colSum = 0 for (row = 0 { colSum = colSum + scores[row][col] } cout << "The total of the scores in column " << col + 1 << " is " << colSum << endl colAverages[col] = colSum / 5.0 cout << "The average of this column is " << colAverages[col] << endl } return 0 }// end of main Sheet1 Page 3 row < 5 row++) col < 3 col++) row < 5 row++) col < 3 col++) // moving cursor to next row Sheet1 Page 4 row < 5 row++) col < 3 col++) col < 3 col++) row < 5 row++)...
View Full Document

{[ snackBarMessage ]}

### Page1 / 4

2D_arrays_complete - Page 2 for(row = 0 rowSum = 0 r...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online