



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A lecture note from a computer science 106 or computing in engineering and science course, dated may 9, 2006. It discusses the concepts of two-dimensional arrays, their notations, declarations, and applications. The document also covers passing two-dimensional arrays to functions and higher-dimensional arrays. It includes examples and exercises.
Typology: Slides
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Larry Caretto Computer Science 106
2
3
4
5
7
M tot 208 316 265 202 991
Op tot
Op 5
Op 4
Op 3
Op 2
Op 1
Op 0
9
10
int outMach[maxMach]; for (int mac = 0; mac < maxMach; mac++) { outMach[mac] = 0; for (int op = 0; op < maxOp; op++) {outMach[mac] += output[op][mac];} cout << “Total machine “ << mac << << “ output is “<<outMach[mac]; }
11
int outOp[maxOp]; for ( int op = 0; op < maxOp; op++ ) { outOp[op] = 0; for ( int m = 0; m < maxMach; m++ ) { outOp[op] += output[op][m]; } cout << “Total operator “ << op << “ output is “ << outOp[op]; } 12
19
20
21
23
int getSums( int output[][maxMach], int opSum[], int machSum[], int Nop, int Nmach) { int total = 0; for ( int op = 0; op < Nop; op++ ) { opSum[op] = 0; for ( int m = 0; m < Nmach; m++ ) opSum[op] += output[op][m];
total += opSum[op]; } // continues on next chart 24
for ( int m = 0; m < Nmach; m++ ) { machSum[m] = 0; for ( int op = 0; op < Nop; op++ ) machSum[op] += output[op][m]; } return total; } // closes function opening brace
25
const int maxMach = 10, maxOp = 10;
int output[maxOp][maxMach], opSum[maxOp], machSum[maxMach]; 26
ifstream inFile( “production.dat” ); inFile >> Nop >> Nmach; for (op = 0; op < Nop; op++ ) for ( m = 0; m < Nmach; m++ ) infile >> output[op][m];
27
28
for (i = 0; i < 3; i++) cin >> x[i] >> y[i];
29
ifstream inFile(“production.dat”); inFile >> Nop >> Nmach; for (op = 0; op < Nop; op++ ) { for ( m = 0; m < Nmach; m++ ) { inFile >> output[op][m]; } }