Professional Documents
Culture Documents
Programming Logic and Design Comprehensive 7Th Edition Joyce Farrell Test Bank Full Chapter PDF
Programming Logic and Design Comprehensive 7Th Edition Joyce Farrell Test Bank Full Chapter PDF
TRUE/FALSE
1. Many newer programming languages such as C++, Java, and C# use subscript 1 to access the first
element of the array.
2. You use subscripts 1 through 10 to access the elements in a ten element array.
3. Many newer programming languages such as C++, Java, and C# use the bracket notation for arrays.
7. You can improve the efficiency of a program by leaving a loop as soon as a match is found in the
array.
9. When you have a five element array and use subscript 8, your subscript is said to be out of bounds.
10. The for loop is a good tool when working with arrays because you frequently need to process every
element of an array from beginning to end.
MULTIPLE CHOICE
8. A program contains an array that holds all the names of the days of the week. Which of the following
is true?
a. The highest subscript is 6. c. The lowest subscript is 1.
b. The highest subscript is 7. d. The highest subscript is 12.
ANS: A PTS: 1 REF: 214
12. Named ____ hold values that do not change during a program’s execution.
a. constants c. objects
b. variables d. items
ANS: A PTS: 1 REF: 224
13. Besides making your code easier to modify, using a ____ makes the code easier to understand.
a. standard constant c. literal constant
b. named constant d. named variable
ANS: B PTS: 1 REF: 224
14. One advantage to using a named constant is that the statement becomes ____.
a. self-perpetuating c. self-referencing
b. self-documenting d. self-mitigating
ANS: B PTS: 1 REF: 225
15. When you search through a list from one end to the other, you are performing a ____.
a. linear search c. quadratic search
b. binary search d. single lookup
ANS: A PTS: 1 REF: 226
16. If you declare a variable to be Boolean, you can set its value to ____.
a. any number c. any integer
b. true or false d. 1 or -1
ANS: B PTS: 1 REF: 229
19. Parallel arrays are most useful when value pairs have a(n) ____ relationship.
a. direct c. linked
b. indirect d. tiered
ANS: B PTS: 1 REF: 234
20. A ____ search starts looking in the middle of a sorted list, and then determines whether it should
continue higher or lower.
a. linear c. quadratic
b. binary d. single lookup
ANS: B PTS: 1 REF: 236
21. To search an array for a(n) ____ match, you can store either the highest or lowest value
of each range for comparison.
a. flag c. subscript
b. index d. range
ANS: D PTS: 1 REF: 238-240
23. The number of bytes in an array is always a multiple of the number of ____ in an array.
a. subscripts c. iterators
b. elements d. indexes
ANS: B PTS: 1 REF: 241
24. In every programming language, when you access data stored in an array, it is important to use a ____
containing a value that accesses memory occupied by the array.
a. superscript c. key
b. subscript d. condition
ANS: B PTS: 1 REF: 241
25. When a subscript is not within the range of acceptable subscripts, it is said to be ____.
a. a superscript c. out of bounds
b. flagged d. indexed
ANS: C PTS: 1 REF: 243
COMPLETION
1. Use a(n) ____________________ to indicate the position of a particular item within an array.
ANS: subscript
2. All array elements have the same ____________________ name, but each individual element also has
a unique subscript indicating how far away it is from the first element.
ANS: group
ANS: constants
5. A(n) ____________________ is a variable set to indicate whether some event has occurred.
ANS: flag
MATCHING
ANS:
An array is a series or list of variables in computer memory, all of which have the same name and data
type but are differentiated with special numbers called subscripts. Usually, all the values in an array
have something in common; for example, they might represent a list of employee ID numbers or a list
of prices for items a store sells. A subscript, also called an index, is a number that indicates the
position of a particular item within an array.
Whenever you require multiple storage locations for objects, you are using a real-life counterpart of a
programming array. For example, if you store important papers in a series of file folders and label each
folder with a consecutive letter of the alphabet, then you are using the equivalent of an array.
ANS:
All array elements have the same group name, but each individual element also has a unique subscript
indicating how far away it is from the first element. Therefore, any array’s subscripts are always a
sequence of integers such as 0 through 4 or 0 through 9.
Depending on the syntax rules of the programming language you use, you place the subscript within
parentheses or square brackets following the group name.
ANS:
Learning to use arrays correctly can make many programming tasks far more efficient and
professional. When you understand how to use arrays, you will be able to provide elegant solutions to
problems that otherwise would require tedious programming steps.
ANS:
• To hold the size of an array
• As the array values
• As a subscript
ANS:
The technique for verifying that an item number exists involves setting a subscript to 0 and setting a
flag variable to indicate that you have not yet determined whether the customer’s order is valid. A flag
is a variable that you set to indicate whether some event has occurred; frequently it holds a true or false
value. For example, you can set a string variable named foundIt to “N”, indicating “No”. Then you
compare the customer’s ordered item number to the first item in the array. If the customer-ordered
item matches the first item in the array, you can set the flag variable to “Y”, or any other value that is
not “N”. If the items do not match, you increase the subscript and continue to look down the list of
numbers stored in the array. If you check all six valid item numbers and the customer item matches
none of them, then the flag variable foundIt still holds the value “N”. If the flag variable is “N”
after you have looked through the entire list, you can issue an error message indicating that no match
was ever found.
ANS:
Leaving the loop as soon as a match is found improves the program’s efficiency. The larger the array,
the more beneficial it becomes to exit the searching loop as soon as you find the desired value.
7. Consider a mail-order business in which customers get a discount based on the quantity they order. In
writing a program to compute the discount based on a customer’s order quantity, why is it not a good
idea to construct an array with as many elements as a customer might want to order, and store the
appropriate discount associated with each number?
ANS:
This approach has at least three drawbacks:
• It requires a very large array that uses a lot of memory.
• You must store the same value repeatedly. For example, each of the first nine elements receives the
same value, 0, and each of the next four elements receives the same value, 10.
• How do you know when you have enough array elements? Is a customer order quantity of 75 items
enough? What if a customer orders 100 or 1,000 items? No matter how many elements you place in
the array, there’s always a chance that a customer will order more.
ANS:
When using an array to store range limits, you use a loop to make a series of comparisons that would
otherwise require many separate decisions. The program that determines customer discount rates is
written using fewer instructions than would be required if you did not use an array, and modifications
to your method will be easier to make in the future.
9. What happens when a beginning programmer forgets that array subscripts start with 0?
ANS:
A common error by beginning programmers is to forget that array subscripts start with 0. If you
assume that an array’s first subscript is 1, you will always be “off by one” in your array manipulation.
PTS: 1 REF: 241 TOP: Critical Thinking
10. What happens if a subscript value is negative or higher than the number of elements in an array?
ANS:
Some programming languages will stop execution of the program and issue an error message. Other
programming languages will not issue an error message but will access a value in a memory location
that is outside the area occupied by the array. That area might contain garbage, or worse, it
accidentally might contain the name of an incorrect month. Either way, a logical error occurs.