assn4_soln - MIT OpenCourseWare http:/ocw.mit.edu 6.096...

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

MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms .

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

View Full Document
Massachusetts Institute of Technology 6.096 Lab 4 Solutions 1. (15 points) #include <iostream> using namespace std; int main() { int grades[6][5] = { {97, 75, 87, 56, 88}, {76, 84, 88, 59, 99}, {85, 86, 82, 81, 88}, {95, 92, 97, 97, 44}, {66, 74, 82, 60, 85}, {82, 73, 96, 32, 77} }; double averages[6]; for (int i = 0; i < 6; i++) { int sum = 0; for (int j = 0; j < 5; j++) { sum += grades[i][j]; } averages[i] = sum/5.0; } for (int k = 0; k < 6; k++) cout << "Student " << k << " has an average of " << averages[k] << endl; return 0; } 2. (5 points) void average( int grades[][5], const int rows, const int columns, double averages[] ) { for (int i = 0; i < rows; i++) { int sum = 0; for (int j = 0; j < columns; j++) { sum += grades[i][j]; } average [i] = sum / static_cast<double>(columns); } } 3. (10 points) void printTTTBoard(int array[][3]) {
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/14/2011 for the course DDDD h0322 taught by Professor Whoknow during the Spring '11 term at Bina Nusantara University.

Page1 / 4

assn4_soln - MIT OpenCourseWare http:/ocw.mit.edu 6.096...

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

View Full Document
Ask a homework question - tutors are online