Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. When an array name is passed to a function, what is actually being passed? A)

ID: 3641892 • Letter: 1

Question

1. When an array name is passed to a function, what is actually being passed?
A) the address of the array
B) a copy of the array is made in the parameter variable of he function
C) depends - sometimes an address is being passed (pass by reference), sometimes pass by value (a copy is being made)
D) None of these

2. Array elements must be ________ before a binary search can be performed.
A) summed
B) sorted
C) set to zero
D) positive numbers
E) None of these

3. Using a linear search to find a value that is stored in the last element of an array of 20,000 elements, ________ element(s) must be compared.
A) only half
B) only the first
C) 2000
D) 20,000
E) None of these

4. The advantage of a linear search is its:
A) complexity
B) simplicity
C) speed
D) efficiency
E) None of these

5. To access an array element, use the array name and the element's:
A) subscript
B) data type
C) name
D) value
E) None of these

6. The name of an array stores the ________ of the first array element.
A) element number
B) data type
C) value
D) memory address
E) None of these

7. How many elements does the following array have?

int bugs[1000];

A) 1001
B) 1000
C) 999
D) cannot tell from the code

8. What will the following code display?

int numbers[4] = { 99, 87 };
cout << numbers[3] << endl;

A) 0
B) garbage
C) 87
D) This code will not compile.

9. A two-dimensional array of characters can contain:
A) uninitialized elements
B) strings of different lengths
C) strings of the same length
D) All of these
E) None of these

10. An array of string objects that will hold 5 names would be declared using which statement?
A) string names5;
B) string names[5];
C) string names(5);
D) String[5] names;
E) None of these will work.

11. A two-dimensional array can have elements of ________ data type(s).
A) two
B) four
C) one
D) Any of these
E) None of these

12. What will the following code display?

int numbers[ ] = { 99, 87, 66, 55, 101 };
for (int i = 1; i < 4; i++)
cout << numbers[i] << endl;

A) 99
87
66
55
101
B) 87
66
55
C) 87
66
55
101
D) Nothing. This code has an error.

13. To assign the contents of one array to another, you must use:
A) the equality operator with the array names
B) the assignment operator with the array names
C) a loop to assign the elements of one array to the other array
D) Any of these
E) None of these

14. A two-dimensional array is like ________ put together.
A) two arrays of different types
B) several identical arrays
C) an array and a function
D) two functions
E) None of these

15. The amount of memory used by an array depends upon the array's data type and the number of elements in the array.
A) True
B) False
16. Given the following declaration, where is 77 stored in the scores array?

int scores[ ]={83, 62, 77, 97};

A) scores [4]
B) scores [0]
C) scores [1]
D) scores [2]

17. The statement

double money[25.00];

is a valid C++ array definition.
A) True
B) False

18. An array with no elements is:
A) automatically furnished one value -- the null terminator
B) legal in C++
C) automatically furnished one element, with a value of zero
D) illegal in C++
E) None of these

19. If an array is partially initialized, the uninitialized elements will be set to zero.
A) True
B) False

20. An array can store a group of values, but the values must be:
A) each of a different data type
B) integers
C) constants
D) the same data type
E) None of these

21. A binary search begins with the ________ element of an array.
A) middle
B) last
C) first
D) largest
E) None of these

22. The advantage of a linear search is its:
A) complexity
B) simplicity
C) speed
D) efficiency
E) None of these

23. Before you can perform a bubble sort, the data must be stored in descending order.
A) True
B) False

24. Define a two dimensional array named settings large enough to hold the table of data below. Initialize the array with the values in the table.



12 24 32 21 42
14 67 87 65 90
19 1 24 12 8




25. Write a function called displayArray7. The function should accept as two dimensional array as an argument and display its contents on the screen. The function should work with any of the following arrays:



int hours[5][7];

int stamps[8][7];

int autos[12][7];

int cats[50][7];

Explanation / Answer

Solution:

1) C
2) B
3) D
4) B
5) B
6) D
7) C
8) B
9) B
10) B
11) B
12) B
13) C
14) D
15) A
16) D
17) B
18) A
19) B
20) D
21) D
22) B
23) B


24)

void Scores(int Scores [][], int& numa, int& numB, ifstream& myin)
{

int numa[12,14,32,21,42], numb[14,67,87,65,90];
myin >> numA>> numB;
int X, Y;
for (A = 0; X < numA; A++)
{
for (Y = 0; Y < numB; B++)
myin >> Y[A][B];
Scores[]=19 1 24 12 8 ;
}
return;
}

25)


void displayArray7()
{
for(int i=0;i{ System.out.print("| ");
for(int j=0;j { System.out.print(arr[i][j]+" "); }
System.out.println("| "); }
}