You are on page 1of 9

Test Bank for Just Enough Programming Logic and Design, 2nd Edition

Test Bank for Just Enough Programming Logic and


Design, 2nd Edition

To download the complete and accurate content document, go to:


https://testbankbell.com/download/test-bank-for-just-enough-programming-logic-and-
design-2nd-edition/

Visit TestBankBell.com to get complete for all chapters


Chapter 5: Arrays

TRUE/FALSE

1. Each array element occupies an area in memory next to the others.

ANS: T PTS: 1 REF: 144

2. All the variables in an array have the same name and data type.

ANS: T PTS: 1 REF: 144

3. If you assume an array’s first subscript is 0, you will always be “off by one” in your array
manipulation.

ANS: F PTS: 1 REF: 145

4. Subscript values can be negative integers in all languages.

ANS: F PTS: 1 REF: 145

5. You cannot initialize array elements when you declare the array.

ANS: F PTS: 1 REF: 145

6. In many languages, when you declare an array, a constant that represents the array size is
automatically created for you.

ANS: T PTS: 1 REF: 154

7. The values stored in arrays should never be constants.

ANS: F PTS: 1 REF: 154

8. When you create parallel arrays, each array must be of the same data type.

ANS: F PTS: 1 REF: 158

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.

ANS: F PTS: 1 REF: 162

10. As with a while loop, when you use a for loop, you must be careful to stay within array bounds.

ANS: T PTS: 1 REF: 165

MULTIPLE CHOICE

1. A(n) ____ is a contiguous series of variables in computer memory.


a. collection c. vector
b. matrix d. array
ANS: D PTS: 1 REF: 144

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

4. Each separate array variable is one ____ of the array.


a. element c. index
b. aspect d. member
ANS: A 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

6. All array elements have the same ____ name.


a. group c. structure
b. target d. collection
ANS: A 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

8. Any array’s subscripts are always a ____ of integers.


a. group c. list
b. sequence d. range
ANS: B PTS: 1 REF: 144

9. Subscripts begin with a value of ____.


a. -1 c. 1
b. 0 d. the number of elements in the array
ANS: B 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

13. What is TRUE about the following array?


num someVals[5] = 1, 3, 5, 7, 9
a. someVals[1] has the value of 1 c. There are 6 elements in this array.
b. someVals[1] has the value of 3 d. someVals[3] has the value of 3
ANS: B 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

20. Frequently, a flag holds a ____ value.


a. subscript c. string
b. true or false d. junk
ANS: B 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-Based Critical Thinking Questions

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

a. for count 0 to SIZE + 1 step 1


b. for count 0 to SIZE - 1 step 1
c. for count 0 to SIZE - 1 step
d. for count 0 to SIZE - 1 step -1
ANS: B PTS: 1 REF: 166 TOP: Critical Thinking

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

a. Change the while to:


while count < 7
b. move count = count + 1 after the endwhile
c. Change the total = to:
total = scores + scores[count]
d. Change the total = to:
total = total + scores[count]
ANS: D PTS: 1 REF: 153 TOP: Critical Thinking

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:

minimum points to earn an A is 900


minimum points to earn a B is 800
minimum points to earn a C is 700
minimum points to earn a D is 600
below 600 earns an F

The points array is defined as follows: num points[5] = 900,800,700,600,0


How should the grades array be defined?
a. num grades[5] = A,B,C,D,F
b. string grades[5] = “A”,”B”,”C”,”D”,”F”
c. num grades[5] = “A”,”B”,”C”,”D”,”F”
d. string grades[5] = “F”,”D”,”C”,”B”,”A”
ANS: B PTS: 1 REF: 158-162 TOP: Critical Thinking

34. The following pseudocode checks if an item number is valid:


start
Declarations
num sub = 0
num SIZE = 5
num VALID_ITEM [5] = 27,53,84,89,95
string foundIt = "N"
input item
while sub < SIZE
if item = VALID_ITEM[sub] then
foundIt = "Y"
endif
sub = sub +1
endwhile
if foundIt = "Y" then
output “Valid item number”
else
output “Invalid item number”
endif
stop

Which while loop makes this more efficient?


a. while sub < SIZE AND foundIt = "N"
b. while sub < SIZE AND foundIt > "N"
c. while sub < SIZE AND foundIt = "Y"
d. The while loop is already efficient
ANS: A PTS: 1 REF: 163 TOP: Critical Thinking

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

PTS: 1 REF: 153 TOP: Critical Thinking

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

PTS: 1 REF: 153 TOP: Critical Thinking

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"

PTS: 1 REF: 154 TOP: Critical Thinking

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

PTS: 1 REF: 166 TOP: Critical Thinking

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

PTS: 1 REF: 166 TOP: Critical Thinking

Visit TestBankBell.com to get complete for all chapters

You might also like