wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz 8: Arrays&Vector

Total questions: 10

Worksheet time: 6mins

Name
Class
Date
1.

Declare a string array "score" that has 57 elements.

(a)  

2.

Given the following For loop, what is the appropriate declaration for the integer array "matrix"?


for (n = 0; n <= 81; n++)

cout << matrix[n];

a)

int matrix[80];

b)

int matrix[82];

c)

int matrix[79];

d)

int matrix[81];

3.

Given the following declarations, which of the following computes the sum of all the elements in "beta"?


int beta[24];

int sum= 0;

a)

for (index=1; index <= 24; index++)

sum = sum+ beta[index];

b)

for (index=0; index < 24; index++)

sum = sum+ beta[index];

c)

for (index=0; index < 24; index++)

sum = sum+ beta;

d)

for (index=1; index <= 24; index++)

sum = sum+ beta;

4.

Given the following function prototype and the array declaration:


float ComputeSomething (short[], int );

short beta[39];


which of the following is the activation statement that calls the function "ComputeSomething" with the array "beta" and prints the returned value?

a)

cout << ComputeSomething(beta, 39);

b)

ComputeSomething(beta, 39);

c)

ComputeSomething(beta[39], 39);

d)

cout << ComputeSomething(beta[39], 39);

5.

The following program code is the function definition of PrintArray which prints an array of double type with "sizeOfArray" elements.


void PrintArray( _________________________)

{

for (int i=0; i< sizeOfArray; i++)

cout << i << gamma[i] << endl;

}


Which of the following is the correct choice for the blank?

a)

gamma[], sizeOfArray

b)

int gamma[], int sizeOfArray

c)

double gamma[], int sizeOfArray

d)

double gamma, int sizeOfArray

6.

Declare an integer array "matrix" that is a two-dimensional array of 91 rows and 25 columns.

(a)  

7.

Which of the following is the correct function prototype for a void function named DisplayThis that has three parameters where the first parameter is a two-dimensional array and the rest are integers?

a)

void DisplayThis ( double [5 ][10], int, int )

b)

void DisplayThis ( double [10][ ], int, int )

c)

void DisplayThis ( double [10], int, int );

d)

void DisplayThis ( double [ ][10], int, int );

8.

Given the following function prototype and the array declaration:


float SumOfArr ( float anArray[ ][45], int rowSize, int colSize);

float arr[90][45];


which of the following is the activation statement that calls the function "SumOfArr" with the array "arr" and prints the returned value?

a)

cout << SumOfArr(arr, 90, 45);

b)

cout << SumOfArr(arr[90][45]);

c)

SumOfArr(arr[ ][45], 90, 45);

d)

cout << SumOfArr(arr[90][45], 90, 45);

9.

Which of the following C++ statements adds a new element to the end of the vector Scores?

a)

cores.push(score);

b)

Scores.push_back(score);

c)

Scores.at(score);

d)

Scores.begin(score);

10.

Given the following vector in C++, how would you access the seventh element within the vector:


vector <int> ages;

a)

cout << ages[7] << endl;

b)

cout << ages.begin(7) << endl;

c)

cout << ages.at(7) << endl;

d)

cout << ages.at(6) << endl;