SYCS-135� Introduction to Programming

Quiz 11 - 11/29/99

 

 

 

Name:� _____Solutions______________________��������������������������� ID:� __________________����������������������������� �����������������������������������

�

1.[2] Write the C++ statement that would declare a data type that is comprised of� a

�2 dimensional array of 20 integers (5 row and 4 columns).� The name of the used defined type should be matrix.

 

_______typedef__int� matrix[5][4]_________________________________________

 

 

�2. [2]� Write the C++ statement that would declare a list data type named

matrix-array.� This homogeneous collection of components should hold five (5) matrix components:�

����������� �

����������� _______typedef__matrix__matrix_array[5]__________________________________

����������� __________________________________________________________________

�����������

3. [6] Write the C++ statements that would declare a variable of the type defined in problem 1.� Name this variable sum_matrix.� Next, declare a variable of the type defined in problem 2. Name this variable detail_matrix_array.� Assign the value 1 to each integer component of detail_matrix_array. Finally, write the C++ code that adds each of the five corresponding elements of the detail_matrix_array and places the sum into the corresponding element in sum_matrix. For, example the five� [0] [0] elements in each of the matrix in detail_matrix_array should be added together and the sum placed in the [0] [0] element of sum_matrix.

 

���� ________matrix__sum_matrix___________________________________________

����������� ________matrix_array__detail_matrix_array; _______________________________

����������� ________for_(int_I = 0; I < 5; I++) ______________________________________

����������� ______________for( int j = 0; j < 5; j++)__________________________________

__________________for(int k = 0; k <4; k++)_____________________________

__________________����������� detail matrix array[I][j][k] = 1;������ _______________

__________________________________________________________________

_��������� ��� for (int I = 0; I < 5; I++)_______________________________________

________������� for (int j = 0; j < 5; j++)____________________________________

����������� ______{_____________________________________________________

����������� _______��������� sum matrix[I][j] = 0;_________________________________

����������� ____________for (int k = 0; k < 4; k++)____________________________

__________________����������� sum matrix[I][j] += detail matrix array[I][j][k];_______

����������� ______}_____________________________________________________

__________________________________________________________________

����������� _______� ____________________________________________________

�����������