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

Info icon This 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 **************
Image of page 1

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

View Full Document Right Arrow Icon
Sheet1
Image of page 2
Image of page 3

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

View Full Document Right Arrow Icon
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 << "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 ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern