Ch5 Verified Test Bank Repetition Structures: Looping - Practice Test Bank | Prelude Programming 6e Venit by Stewart Venit. DOCX document preview.
Test Bank for Prelude to Programming Chapter 5
MULTIPLE CHOICE
1. Which of the following is a true statement?
a. | (15 * 2 <= 30) AND (15 – 2 > 30) |
b. | (15 * 2 <= 30) OR (15 – 2 > 30) |
c. | (15 * 2 > 30) AND (15 – 2 < 30) |
d. | (15 * 2 < 30) OR (15 – 2 > 30) |
2. Given that the variables MyName and YourName are defined as follows, which expression is true?
MyName = “Elizabeth” and YourName = “Mike”
a. | MyName > YourName |
b. | MyName == YourName |
c. | YourName <= MyName |
d. | YourName >= MyName |
3. What will be displayed if code corresponding to the following pseudocode is executed?
Set Number = 4
Repeat
Write 2 * Number
Set Number = Number + 2
Until Number = 8
a. | 8 12 16 | 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 |
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 |
6. Which of the following is not a type of loop?
a. | While |
b. | For |
c. | Repeat...Until |
d. | Do...While |
e. | all of the above are types of loops |
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 |
8. If Number = 7, what will be displayed after code corresponding to the following pseudocode is run?
For (Count = 5; Count <= Number; Count++)
Write Count, Count * 2
End For
a. | 5 10 6 12 7 14 | b. | 5 10 6 12 | c. | 5 10 7 14 | d. | 5 7 10 14 |
9. 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 | b. | 2 4 6 8 | c. | 4 6 8 10 | d. | 4 6 8 |
10. What will be displayed after code corresponding to the following pseudocode is run?
Write “Loops are fun!”
For (Count = 8; Count > 4; Count–2)
Write “Hooray!”
End For
a. | Loops are fun! Hooray! Hooray! Hooray! | b. | Loops are fun! Hooray! Hooray! |
c. | Loops are fun! | 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. |
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 |
13. What input can cause this loop to end?
Declare Number, ComputerNumber As Integer
Do
Write “Please enter a number: “
Input Number
ComputerNumber = Number + 1
Write Number
While Number <= ComputerNumber
Write “The End”
a. | 12 |
b. | 0 |
c. | 1 |
d. | Nothing would cause this loop to end; it is an infinite loop. |
14. If A = 5 and B = 3, what will be displayed when code corresponding to the following pseudocode is run?
Do
Write A^2
Set A = A - 1
While A <= B
a. | 9 9 9 | b. | 25 16 9 | c. | 25 15 | d. | 25 16 9 4 |
15. If Count = 1 and X = 3, what will be displayed when code corresponding to the following pseudocode is run?
Do
Set Y = Count + X
Write Y
Set Count = Count + 1
WhileCount <= X
a. | 4 5 6 | b. | 1 3 5 | c. | 4 5 6 7 | d. | 3 4 5 6 |
16. What statements are in the body of the following loop?
Set Number = 12
For (I = 1; I <= 15; I++)
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 “That’s a good number.” Write “Bye bye.” |
d. | Input Number |
17. If N = 5, what is displayed when the following pseudocode is coded and run?
Set A = 2
For (B = 1; B <=N; B++)
Set A = A + 2 * B
End For
Write A
a. | 22 | b. | 16 | c. | 32 | d. | 18 |
18. What is the value of Number, given the following: A = 3.2, B = 6, C = 8
Set Number = Floor(A + C / B)
a. | 4.87 | b. | 4 | c. | 4.9 | d. | 1.125 |
19. What is the value of Number, given the following: A = 4.2, B = 6, C = 1.5
Set Number = Ceiling(A + B * C)
a. | 14 | b. | 13 | c. | 13.2 | d. | 15 |
20. What is the value of Number, given the following: A = 2.3, B = 3.8
Set Number = Floor(Ceiling(A) * B)
a. | 6 | b. | 8.74 | c. | 8 | d. | 6.1 |
TRUE/FALSE
1. True/False: If Number = 7, then the following statement is true:
(Number * Number) <= (2 * Number).
2. True/False: Is the following statement true or false: “G” != “G”.
3. True/False: If MyName = “Liz” and YourName = “Stewart” then is the following statement true or false?
(MyName < YourName) OR (MyName >= YourName)
4. True/False: If a condition in a post-test loop can never be met, the loop is an infinite loop.
5. True/False: If a condition in a pre-test loop can never be met, the loop is an infinite loop.
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; X <= 10; X+2)
7. True/False: If the following statement is the first line of a For loop, N is the limit value.
For (X = 1; X <= N; X+3)
8. True/False: The body of a post-test loop is always executed at least once.
9. True/False: The body of a pre-test loop is always executed at least once.
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.
- True/False: In the following statement, X is the initial value:
For (X = N; X <= Y; X++)
12. True/False: A step value in a loop can be either a positive or a negative number.
13. True/False: Is the following statement true or false?
Int(6.89) = 6.
14. True/False: Is the following statement true or false?
(50 <= 100) AND (9 > 12).
15. True/False: There are six relational operators.
- True/False: Both Repeat...Until and Do...While loops are post-test loops.
17. True/False: The expression Ceiling(5 + 6.2) evaluates to 11.
18. True/False: The expression Floor(8.2 * 4) evaluates to 32.
19. True/False: If X is an integer variable, then the expression Int(X^2 – 4 * X) is valid.
20. True/False: If X = 5.6, then the expression Int(X) == X evaluates to 6.
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 _(less/greater)_ than the limit value.
2. To __________ data means to ensure that the data are in the proper range.
- If Number1 = 19.86 and Number2 = 2.94, then:
Int(Number1) + Int(Number2) = __________.
- If Number1 = 19.86 and Number2 = 2.94 then:
Int(Number1 + Number2) = __________. .
5. If a loop contains a test condition that can never be met, it is called a(n) __________ loop.
6. For readability, most programs __________ the body of a loop.
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.
8. A variable that keeps track of the number of passes through a loop is known as a(n) __________.
9. The number of passes through a loop is known as the number of loop __________.
10. When a loop counter is set to its first value, it is said to be __________.
11. A variable that holds the accumulated result of a sum is called a(n) __________.
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.
13. If Number1 = 12.2 and Number2 = 13.3, the expression:
Floor(Number1) + Ceiling(Number2)
evaluates to __________.
14. If Number1 = 12.2 and Number2 = 13.3, the expression
Int(Ceiling(Number1) + Ceiling(Number2))
evaluates to __________..
15. If a For loop’s increment is positive, then the body of the loop will not be executed if the
initial value is __________ _________ the limiting value.