2D_arrays_complete

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

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

View Full Document Right Arrow Icon
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 **************
Background image of page 1

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

View Full DocumentRight Arrow Icon
Sheet1
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
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 &lt;&lt; &quot;The total of the scores in row &quot; &lt;&lt; row + 1 &lt;&lt; &quot; is &quot; &lt;&lt; rowSum &lt;&lt; endl cout &lt;&lt; &quot;The average of this row is &quot; &lt;&lt; rowSum / 3.0 &lt;&lt; endl } // ****** computing column averages ***************** for (col = 0 { colSum = 0 for (row = 0 { colSum = colSum + scores[row][col] } cout &lt;&lt; &quot;The total of the scores in column &quot; &lt;&lt; col + 1 &lt;&lt; &quot; is &quot; &lt;&lt; colSum &lt;&lt; endl colAverages[col] = colSum / 5.0 cout &lt;&lt; &quot;The average of this column is &quot; &lt;&lt; colAverages[col] &lt;&lt; endl } return 0 }// end of main Sheet1 Page 3 row &lt; 5 row++) col &lt; 3 col++) row &lt; 5 row++) col &lt; 3 col++) // moving cursor to next row Sheet1 Page 4 row &lt; 5 row++) col &lt; 3 col++) col &lt; 3 col++) row &lt; 5 row++)...
View Full Document

Page1 / 4

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online