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

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

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

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

View Full DocumentRight Arrow Icon
MASSACHUSETTS INSTITUTE OF TECHNOLOGY 6.096: Introduction to C++ IAP 2009 PROBLEM SET 4 Initializing multidimensional arrays: The examples of multidimensional arrays in lecture did not give the syntax for initializing them. The way to assign a multidimensional array in the array declaration is as follows: int matrix[2][3] = { {1, 2, 3}, {4, 5, 6} }; Inside the inner braces, commas still separate individual numbers. Outside, they separate rows of the array. After this declaration, matrix[0][1] will return the value 2 . Each one of the rows is initialized like a regular array. For instance, if instead of {1, 2, 3} we’d put {1} , the second and third elements of the first row would have been initialized to 0. 1. Write a program that declares the 2D array of student test grades shown below, and stores the students’ averages in a 1D array. Each row in the 2D array represents the grades of a particular student (their parents uncreatively named them Student 0, Student 1, etc.). Output the array of averages. int studentGrades[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} }; Multidimensional arrays as arguments: The syntax for passing multidimensional arrays as arguments is very similar to that of passing regular arrays. The main difference is that you need to include the number of columns in the function definition. For instance, a function that takes a 2-dimensional array with 3 columns might be declared as follows:
Background image of page 2
Image of page 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 - 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 Right Arrow Icon
Ask a homework question - tutors are online