2D_arrays_complete

# 2D_arrays_complete - CMPSC 101 Class#14 Demo#1a#include...

• Notes
• 4

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.

Sheet1

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

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

• Fall '07
• DROBISH,RENEE
• #, #include, Row, ifstream infile

{[ snackBarMessage ]}

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern