Professional Documents
Culture Documents
TRUE/FALSE
2. All the variables in an array have the same name and data type.
3. If you assume an array’s first subscript is 0, you will always be “off by one” in your array
manipulation.
5. You cannot initialize array elements when you declare the array.
6. In many languages, when you declare an array, a constant that represents the array size is
automatically created for you.
8. When you create parallel arrays, each array must be of the same data type.
9. The smaller the array, the more beneficial it becomes to exit the searching loop as soon as you find
what you’re looking for.
10. As with a while loop, when you use a for loop, you must be careful to stay within array bounds.
MULTIPLE CHOICE
2. All the variables in an array are differentiated with special numbers called ____.
a. scripts c. elements
b. subscripts d. pointers
ANS: B PTS: 1 REF: 144
3. A(n) ____, also called an index, is a number that indicates the position of a particular item within an
array.
a. indicator c. subscript
b. element d. script
ANS: C PTS: 1 REF: 144
5. The number of elements an array will hold is known as the ____ of the array.
a. bounds c. constraints
b. limits d. size
ANS: D PTS: 1 REF: 144
7. Each individual element in an array has a unique ____ indicating how far away it is from the first
element.
a. indicator c. subscript
b. element d. script
ANS: C PTS: 1 REF: 144
10. In most modern programming languages, the highest subscript you should use with an 8-element array
is ____ .
a. 6 c. 8
b. 7 d. 9
ANS: B PTS: 1 REF: 144-145
11. When declaring an array, depending on the syntax rules of the programming language you use, you
place the subscript within parentheses or ____ following the group name.
a. asterisks c. curly brackets
b. slashes d. square brackets
ANS: D PTS: 1 REF: 145
12. Most programming languages use a statement similar to the following to declare a three-element array
and assign values to it: ____
a. {20, 30, 40} = num someVals[3]
b. num someVals[3] = {someVals}
c. num someVals[] = 20, 30, 40
d. num someVals[3] = 20, 30, 40
ANS: D PTS: 1 REF: 145
14. The true benefit of an array lies in your ability to use a(n) ____ as a subscript to the array.
a. variable c. operator
b. table d. field
ANS: A PTS: 1 REF: 150
15. Learning to use arrays correctly can make many programming tasks far more ____ and professional.
a. confusing c. slick
b. efficient d. literal
ANS: B PTS: 1 REF: 154
16. When working with arrays, you can use ____ in two ways: to hold an array’s size and as the array
values.
a. structures c. constants
b. literals d. strings
ANS: C PTS: 1 REF: 154
17. Besides making your code easier to modify, using a ____ makes the code easier to understand.
a. constant c. named declaration
b. named constant d. named variable
ANS: B PTS: 1 REF: 154
18. When you search through a list from one end to the other, you are performing a ____ search.
a. linear c. quick
b. binary d. Google
ANS: A PTS: 1 REF: 157
19. A ____ is a variable that you set to indicate whether some event has occurred.
a. handler c. flag
b. rudder d. bug
ANS: C PTS: 1 REF: 157
21. In ____ arrays, each element in one array is associated with the element in the same relative position in
the other array.
a. parallel c. grouped
b. related d. combined
ANS: A PTS: 1 REF: 158
22. When you use parallel arrays, two or more arrays contain ____ data.
a. connected c. identical
b. equivalent d. related
ANS: D PTS: 1 REF: 159
23. When you use parallel arrays, a ____ relates the arrays.
a. link c. subscript
b. flag d. script
ANS: C PTS: 1 REF: 159
24. The relationship between an item’s number and its price is a(n) ____ relationship.
a. direct c. hidden
b. indirect d. clear
ANS: B PTS: 1 REF: 161
25. Leaving a loop as soon as a match is found improves the program’s ____.
a. indirect relationships c. simplicity
b. logic d. efficiency
ANS: D PTS: 1 REF: 162
26. A ____ search starts looking in the middle of a sorted list, and then determines whether it should
continue higher or lower.
a. linear c. graphic
b. quick d. binary
ANS: D PTS: 1 REF: 163
27. In Java, C++, and C#, the for loop looks like the following:
a. for(dep = 0; dep++; dep < SIZE)
b. for(dep > SIZE; dep = 0; dep++)
c. for(dep = 0; dep < SIZE; dep++)
d. for(dep = SIZE, dep > 0, dep++)
ANS: C PTS: 1 REF: 166
28. An element in an array is 3 bytes long and there are 10 elements in the array. How big is the array?
a. 30 bytes c. 3 bytes
b. 10 bytes d. Not enough information to determine
ANS: A PTS: 1 REF: 164
29. The ____ is a particularly convenient tool when working with arrays because you frequently need to
process every element of an array from beginning to end.
a. binary search c. for loop
b. range check d. parallel array
ANS: C PTS: 1 REF: 165
30. When you have a six element array and use subscript 6, your subscript is said to be out of ____.
a. bounds c. range
b. scope d. array
ANS: A PTS: 1 REF: 165
Case 1
You have just starting working at Quantum Company. As a new programmer, you have been asked to
review and correct various pseudocode.
31. The following pseudocode is not working correctly. How should the for loop be changed?
start
Declarations
num count = 0
num scores[6] = 0,0,0,0,0,0
num SIZE = 6
for count 0 to SIZE step
input entry
scores[count] = entry
endfor
stop
32. The following pseudocode is not working correctly. The code should total the array elements. What
code needs to be changed?
start
Declarations
num count = 0
num total = 0
num scores[6] = 2,4,6,8,10,12
while count < 6
total = total + scores
count = count + 1
endwhile
stop
33. You are working with parallel arrays to detemine the grade a student earns in a class. The student earns
a grade based on the following:
35. The following pseudocode is not working correctly. What kind of error is this?
start
Declarations
num count = 0
num scores[6] = 0,0,0,0,0,0
num SIZE = 6
for count 0 to SIZE step 1
input entry
scores[count] = entry
endfor
stop
a. out of memory c. out of bounds
b. no match was found d. bounded
ANS: C PTS: 1 REF: 165 TOP: Critical Thinking
SHORT ANSWER
1. Write the pseudocode to define a five element array called “scores,” and then allow a user to enter 5
scores and store them in the array using a while loop.
ANS:
start
Declarations
num count = 0
num scores[5] = 0,0,0,0,0
while count < 5
input entry
scores[count] = entry
count = count + 1
endwhile
stop
2. Write the pseudocode to define and initialize a four element array called “evens,” with even numbers
from 2 to 8, and then find the total of the values in the array using a while loop.
ANS:
start
Declarations
num count = 0
num total = 0
num scores[4] = 2,4,6,8
while count < 4
total = total + scores[count]
Test Bank for Just Enough Programming Logic and Design, 2nd Edition
count = count + 1
endwhile
stop
3. Define and initialize an array that contains the names of the days of the week.
ANS:
string DAYS[7] = "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday", "Sunday"
4. Write the pseudocode to define a six element array called “scores,” and then allow a user to enter 6
scores and store them in the array using a for loop.
ANS:
start
Declarations
num count = 0
num scores[6] = 0,0,0,0,0,0
num SIZE = 6
for count 0 to SIZE - 1 step 1
input entry
scores[count] = entry
endfor
stop
5. Write the pseudocode to define and initialize a five element array called “evens,” with even numbers
from 2 to 10, and then find the total of the values in the array using a for loop.
ANS:
start
Declarations
num count = 0
num evens[5] = 2,4,6,8,10
num SIZE = 5
for count 0 to SIZE - 1 step 1
total = total + evens[count]
count = count + 1
endfor
stop