0% found this document useful (0 votes)
673 views

1D and 2D Array Quiz

This document contains a practice test on arrays in C++ programming. It has four sections with multiple choice, true/false, code tracing, and code conversion questions. The questions cover topics like declaring and initializing arrays, accessing array elements, and using for, while, and do-while loops to iterate through arrays.

Uploaded by

Ryan Olaybal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
673 views

1D and 2D Array Quiz

This document contains a practice test on arrays in C++ programming. It has four sections with multiple choice, true/false, code tracing, and code conversion questions. The questions cover topics like declaring and initializing arrays, accessing array elements, and using for, while, and do-while loops to iterate through arrays.

Uploaded by

Ryan Olaybal
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

BES 213 Programming II 2019. July.

16

Name:

Test II. TRUE/ FALSE. Write TRUE if the statement is correct. Otherwise, write FALSE. ( 7 points)
1. To reserve elements that can hold whole numbers, the declaration double num[ 12 ]; can be used.
2. You must declare a two-dimensional array before you can use it.
3. The first element in a one-dimensional array has a subscript of 0 (zero).
4. A one-dimensional array resembles a table in that the elements are in rows and columns. Each element has the
same data type.
5. You can determine the number of elements in a two-dimensional array by multiplying the number of its rows by
the number of its columns.
6. Each element in a two-dimensional array is identified by a unique combination of two subscripts. The first
subscript represents the element’s row location in the array, and the second subscript represents its column
location.
7. You need to use two loops to access every element in a one-dimensional array.

Test II. MULTIPLE CHOICE. Select the letter that corresponded to the best answer from the choice given. (14 points)
1. Which of the following correctly declares a one dimensional array?
a) int array[10]; c) array{10};
b) int array; d) array array[10];
2. What is the index number of the last element of an array with 9 elements?
a) 9 c) 0
b) 8 d) Programmer-defined
3. Which of the following best describes an array?
a) An array is a series of elements of the c) An array is a series of elements of
same type in contiguous memory different type placed in contiguous
locations memory locations
b) An array is a series of element d) All of the above
4. Which of the following correctly accesses the seventh element stored in a one dimensional array?
a) array[6]; c) array(7);
b) array[7]; d) array;
5. Which of the following statements replaces the last element of a two dimensional array int num[2][5] with 72?
a) num[0][0]= 72; c) num[2][5]=72;
b) num[1][4]=72; d) num[3][6]=72;
6. Which of the following is a two-dimensional array?
a) array anarray[20][20]; c) int array[20, 20];
b) int anarray[20][20]; d) char array[20];
7. Fill in the blanks of the following code fragment so that the elements of the array are printed in reverse order,
starting with the last element.
int number [10]= { 2, 4, 6, 8, 10, 1, 3, 5, 7, 9 };

for ( int index= ________ ; _____________ ; ______________ )


cout<<number[index];
a) index = 0; index < 10; index--
b) index = 10; index < 0; index—
c) index = 9; index > 0; index--
d) index = 9; index >=0; index--
e) index = 10; index >= 0; index--
Test III. PROGRAM TRACING. Determine the output based from the given segment of codes. (14 points)
1. Determine the output based from the given segment of codes
int main ()
{
int array[ ] = {0, 2, 4, 6, 7, 5, 3};
int n, result = 0;
for (n = 0 ;n < 3 ;n++)
{
result += array[n];
}
cout << result;
return 0;
}

2. What is stored in beta after each of the following statements executes?


int beta[3][2];
for (i = 0; i < 3; i++)
for (j = 0; j < 2; j++)
beta [i][j] = i + j;

Test IV. PROGRAM CONVERSION. Convert the given codes in to its equivalent. (15 points)

1. Convert the code found in test III number 2 from using for loop into while loop (outer) do while loop (inner). (10
points)
2. Change the following C++ code from using a while loop to for loop: (5 points)

int num[5], x=1;


while(x<10)
{
cout<<x<<"\t";
cin>> num[x];
x++;
}

You might also like