Extended Prelude to Programming. Test Bank Chapter 4. © 2007 Pearson
Education. 1. Test Bank for Prelude to Programming. Chapter 4. MULTIPLE
CHOICE.
Extended Prelude to Programming
Test Bank Chapter 4
Test Bank for Prelude to Programming
Chapter 4
MULTIPLE CHOICE 1. Which of the following is a true statement? a. (15 * 2 30) b. (15 * 2 30) c. (15 * 2 > 30) AND (15 – 2 < 30) d. (15 * 2 < 30) OR (15 – 2 > 30) ANS: B
2. Given that the variables MyName and YourName are defined as follows, which expression is true?
MyName = “Elizabeth” and YourName = “Mike” YourName YourName = MyName
a. MyName > b. MyName = c. YourName d. YourName ANS: D
3. What will be displayed if code corresponding to the following pseudcode is executed?
Set Number = 4 Repeat Write 2 * Number Set Number = Number + 2 Until Number = 8 a.
8 12 16 ANS: C
b.
4 8 12
c.
8 12
d.
12 16
4. A counter must be: a. a positive number b. a real number c. an integer d. a variable named Count ANS: C
© 2007 Pearson Education
1
Extended Prelude to Programming
Test Bank Chapter 4
5. Given: Count = 23, what is the value of Count after the following statement is executed:
Count = Count + 2 a. 23 b. 25 c. 48 d. 24 ANS: B
6. Which of the following is not a type of loop? a. While b. For c. Repeat d. all of the above are types of loops ANS: D
7. What will be displayed after code corresponding to the following pseudocode is run?
Set Count = 10 While Count > 0 Write Count Set Count = Count – 2 End While a.
10 8 6 4 2
b.
10 8 6 4 2 0
c.
8 6 4 2
d.
8 6 4 2 0
ANS: A
8. What will be displayed after code corresponding to the following pseudocode is run?
Set Count = 2 While Count < 10 Set Count = Count + 2 Write Count End While a.
2 4 6 8 10 ANS: C
b.
2 4 6 8
© 2007 Pearson Education
c.
4 6 8 10
d.
4 6 8
2
Extended Prelude to Programming
Test Bank Chapter 4
9. If Number = 7, what will be displayed after code corresponding to the following pseudocode is run?
For Count = 5 Step 1 To Number Write Count, Count * 2 End For a.
5 10 6 12 7 14 ANS: A
b.
5 10 6 12
c.
5 10 7 14
d.
57 10 14
10. What will be displayed after code corresponding to the following pseudocode is run?
Write “Loops are fun!” For Count = 8 Step -2 to 4 Write “Hooray!” End For a. Loops are fun!
Hooray! Hooray! Hooray! c. Loops are fun! ANS: A
b. Loops are fun!
Hooray! Hooray!
d. nothing will display
11. If Apples = 6, what will be displayed after code corresponding to the following pseudocode is run?
While Apples < 0 Write “You can’t eat “, Apples, “at one time!” End While Write “Goodbye, apple lover.” a. You can’t eat 6 apples at one time! Goodbye, apple lover. b. nothing will display c. You can’t eat apples at one time! d. Goodbye, apple lover. ANS: D
12. If MyNumber = 6.8, what is the value of Int(MyNumber * 4^2)? a. 108.8 b. 108 c. 109 d. this is an illegal operation ANS: B
© 2007 Pearson Education
3
Extended Prelude to Programming
Test Bank Chapter 4
13. What is the output of the code corresponding to the following pseudocode?
For I = 2 Step 1 To 3 For J = 1 Step 1 To 3 Write I, “and “ J End For(J) End For(I) a.
2 and 1 3 and 1
b.
2 2 2 3 3 3
and and and and and and
1 2 3 1 2 3
c.
1 and 1 2 and 2 3 and 3
d.
I and J I and J I and J
ANS: B
14.
What statements are in the body of the following loop?
Set Number = 12 For I = 1 Step 1 To 15 Write “Enter a number: “ Input Number Write “That’s a good number.” End For Write “Bye bye.” a. Set Number = 12
Write “Bye bye.” b. Write “Enter a number: “
Write “That’s a good number.” c. Write “Enter a number: “
Write Write d. Write Input Write
“That’s a good number.” “Bye bye.” “Enter a number: “ Number “That’s a good number.”
ANS: D
15. If N = 5, what is displayed when the following pseudocode is coded and run?
a. 22 ANS: C
Set A = 2 For B = 1 Step 1 To N Set A = A + 2 * B End For Write A b. 16 c. 32
© 2007 Pearson Education
d. 18
4
Extended Prelude to Programming
Test Bank Chapter 4
TRUE/FALSE 1. True/False: If Number = 7, then the following statement is true: (Number * Number) = YourName) 4.
ANS: T 4. True/False: If one For Loop is nested within another, then the limit value for the two loops must be different. ANS: F 5. True/False: Two non-overlapping loops can be nested within a third loop. ANS: T 6. True/False: If the following statement is the first line of a For loop, on the first pass through the loop, X will have the value of 2.
For X = 1 Step 2 to 10 ANS: F 7. True/False: If the following statement is the first line of a For loop, N is the limit value.
For X = 1 Step 3 to N ANS: T 8. True/False: The body of a post-test loop is always executed at least once. ANS: T 9. True/False: The body of a pre-test loop is always executed at least once. ANS: F 10. True/False: In a pre-test loop the test condition is at the bottom, while it is at the top in a post-test loop. ANS: F 11. True/False: In the following statement, X is the initial value:
For X = N Step 2 to Y ANS: F 12. True/False: A step value in a loop can be either a positive or a negative number. ANS: T 13. True/False: Is the following statement true or false? Int(6.89) = 6.
© 2007 Pearson Education
5
Extended Prelude to Programming
Test Bank Chapter 4
ANS: T 14. True/False: Is the following statement true or false? (50 12). ANS: F 15. True/False: There are six relational operators. ANS: T
SHORT ANSWER 1. If the increment of a For loop is negative, then the body of the loop will not be executed if the initial value is __________ than the limit value. ANS: less 2. To __________ data means to ensure that the data are in the proper range. ANS: validate 3. If Number1 = 19.86 and Number2 = 2.04, then: a.
Int(Number1) + Int(Number2) = __________.
ANS: 21 4. If Number1 = 19.86 and Number2 = 2.04 then: a.
Int(Number1 + Number2) = __________. .
ANS: 21 5. If a loop contains a test condition that can never be met, it is called a(n) __________ loop. ANS: infinite 6. For readability, most programs __________ the body of a loop. ANS: indent 7. A loop that is executed a fixed number of times, where that number is known before entering the loop for the first time, is known as a(n) __________ __________ loop. ANS: counter controlled 8. A variable that keeps track of the number of passes through a loop is known as a(n) __________. ANS: counter 9. The number of passes through a loop is known as the number of loop __________. ANS: iterations 10. When a loop counter is set to its first value, it is said to be __________. ANS: initialized 11. When the step value in a loop is positive, the counter is said to be __________. ANS: incremented 12. One way to force a loop to end is to have the user enter a special item, called a(n) ___________ __________ which acts as a signal that input is complete.
© 2007 Pearson Education
6
Extended Prelude to Programming
Test Bank Chapter 4
ANS: sentinel value 13. A sentinel value is also known as a(n) __________ marker. ANS: end-of-data 14. The type of loop that uses two input values (one before the loop is entered and one within the loop) to validate data is a(n) __________-test loop. ANS: pre 15. One way to break out of a loop early, when, for example, a user has entered an incorrect value or entered a specified response, is to use a(n) __________ structure within the loop. ANS: If-Then-Else
© 2007 Pearson Education
7