Ch4 Test Bank Answers Selection Structures: Making Decisions - Practice Test Bank | Prelude Programming 6e Venit by Stewart Venit. DOCX document preview.
Test Bank for Prelude to Programming Chapter 4
MULTIPLE CHOICE
1. Which of the following is not a type of selection structure?
a. | single-alternative |
b. | dual-alternative |
c. | multiple-alternative |
d. | Case or switch |
e. | all of the above are types of selection structures |
2. Given the following program segment, what is the test condition?
Write “Enter your response (Y/N)”
Input Answer
If Answer == “No” Then
Write “Try Again”
Input Answer
End If
Write “Are you having fun yet? (Y/N)”
Input Response
a. | Answer |
b. | Answer == “No” |
c. | Response |
d. | Answer = “Y” |
3. Given the following program segment, if the user inputs “Hooray!” on Line 2, what line will be executed after Line 3?
1. Write “Enter your response (Y/N)”
2. Input Answer
3. If Answer == “No” Then
4. Write “Try Again”
5. Input Answer
6. End If
7. Write “Are you having fun yet?”
8. Input Response
a. | Line 4 |
b. | Line 5 |
c. | Line 7 |
d. | Line 8 |
4. What is the output of code corresponding to the following program segment if Age = 18?
If Age >= 18 Then
Write “You are eligible to vote.”
Else
Set Vote = Age - 18
Write “You can vote in “ + Vote + “years.”
End If
a. | You are eligible to vote. |
b. | You can vote in 18 years. |
c. | You are eligible to vote. You can vote in 18 years. |
d. | You can vote in 0 years. |
5. If MyName = “Bunny” and YourName = “Buddy”, which of the following is not True?
a. | MyName > YourName |
b. | MyName <= YourName |
c. | MyName >= YourName |
d. | YourName < MyName |
6. If X = True and Y = False, which of the following will give a result of True?
a. | X AND Y |
b. | X OR Y |
c. | NOT X OR Y |
d. | NOT X AND NOT Y |
7. If X = 2, Y = 4, and Z = 6, which of the following will give a result of False?
a. | (X < Y) AND (Y < Z) |
b. | (Y > X) AND (Z > X) |
c. | (X > Y * Z) OR (X * Y > Z) |
d. | (X > Y * Z) OR (Z > X * Y) |
8. Given that Jamie worked 50 hours (Hours = 50) last week and earns $10.00 an hour (Rate = 10), how much did Jamie earn last week, before taxes (TotalPay)?
If (Rate >=10) OR (Hours <=40) Then
TotalPay = Hours * Rate
Else
TotalPay = (Hours * Rate)+(Hours–40)*Rate*1.5
End If
a. | $ 500 |
b. | $ 650 |
c. | $ 750 |
d. | $ 400 |
9. Given that Marcy worked 42 hours (Hours = 42) last week and earns $10.00 an hour (Rate = 10), how much did Marcy earn last week, before taxes (TotalPay)?
If (Rate >=10) AND (Hours <=40) Then
TotalPay = Hours * Rate
Else
TotalPay = (40 * Rate) + (Hours – 40) * Rate * 1.5
End If
a. | $ 500 |
b. | $ 420 |
c. | $ 430 |
d. | $ 650 |
10. The term “defensive programming” refers to all of the following except:
a. | ensuring that a division by zero does not take place |
b. | ensuring that input data is within the proper range |
c. | ensuring that there are no compound conditions in a selection structure |
d. | ensuring that a negative number is not input to the Sqrt function |
11. Given that the user input for Response is 3, what would be displayed if code corresponding to the following program segment were run?
Input Response
Select Case Of Response
Case 1:
Write “You’re a newbie”
Break
Case 2:
Write “You’re Number 2”
Break
Case 3:
Write “The door to Sesame Street is open!”
Break
Default
Write “Huh?”
End Case
a. | You’re a newbie |
b. | You’re Number 2 |
c. | The door to Sesame Street is open! |
d. | Huh? |
e. | Nothing would be displayed since Response is not one of the conditions in the Case statement. |
12. A multiple-alternative structure cannot be implemented by using which of the following:
a. | a single If-Then statement |
b. | several If-Then statements |
c. | several If-Then-Else statements |
d. | a single Case statement |
13. Which of the following will test to make sure the number entered by the user into the variable named InRange is between 5 and 50? (i.e., not including 5 or 50)
a. | If (InRange > 5) AND (InRange < 50) Then … |
b. | If (InRange >= 5) AND (InRange <= 50) Then … |
c. | If (InRange > 5) OR (InRange < 50) Then … |
d. | If (InRange >= 5) OR (InRange <= 50) Then… |
14. Given the following program, choose the line necessary to replace the ***’s so that the program segment will ensure that an illegal operation does not occur.
Write “Enter a number: “
Write “The square root of that number will be displayed.”
Input MyNumber
********************
Write “The square root of “ + MyNumber
Write “is: “ + Sqrt(MyNumber)
Else
Write “Illegal operation!”
End If
a. | If MyNumber < 0 |
b. | If MyNumber <= 0 |
c. | If MyNumber >= 0 |
d. | If MyNumber != 0 |
15. Which of the following will make the given statement true?
MyName <= YourName
a. | MyName = “Lizzie” and YourName = “Tizzie” |
b. | MyName = “Lizzie” and YourName = “Lizzie” |
c. | MyName = “Lizzie” and YourName = “LizzieBeth” |
d. | All of the above make the statement true |
16. Which of the following will make the given statement false?
MyAge > YourAge
a. | MyAge = 23, YourAge = 24 |
b. | MyAge = 23, YourAge = 23 |
c. | MyAge = 23, YourAge = 35.6 |
d. | All of the above make the statement false |
17. If MyAge = 30 and YourAge = 40, which of the following is a true statement?
a. | MyAge == “23” AND YourAge == “40” |
b. | MyAge >= YourAge |
c. | NOT(MyAge > YourAge) |
d. | None of the above are a true statement |
18. Which of the following program segments is equivalent to the program segment given below?
If Pay >= 500 Then
Set TaxRate = 0.3
End If
If (Pay >= 300) AND (Pay < 500) Then
Set TaxRate = 0.2
End If
If (Pay >= 100) AND (Pay < 300) Then
Set TaxRate = 0.1
End If
a. | If Pay > 100 Then Set TaxRate = 0.1 Else If Pay > 300 Then Set TaxRate = 0.2 Else If Pay > 500 Then Set TaxRate = 0.3 End If End If |
b. | If Pay >= 500 Then Set TaxRate = 0.3 Else If Pay >= 300 Set TaxRate = 0.2 Else If Pay >= 100 Then Set TaxRate = 0.1 End If End If End If |
c. | If Pay >= 500 Then Set TaxRate = 0.3 Else Set TaxRate = 0.2 If Pay > 100 Then Set TaxRate = 0.1 End If End If |
d. | none of the above are equivalent to the given example |
19. If Number = 8, what will be displayed after the following statement is executed?
Set Reciprocal = 1/Number
Write Reciprocal
a. | 0.125 |
b. | 1/8 |
c. | “Reciprocal” |
d. | An error message |
20. What will be displayed after the following program segment is coded and run, assuming the user enters the number 49 at the prompt?
Write “Enter a number.”
Write “This program will display its square root.”
Input Number
Write “The square root of “+Number+“ is “+Sqrt(Number)+“.”
a. | The square root of 7 is 49. |
b. | The square root of Number is 7. |
c. | The square root of 49 is 7. |
d. | An error message |
TRUE/FALSE
1. True/False: A single-alternative selection structure always contains an Else clause.
2. True/False: The assignment operator and the comparison operator are the same.
3. True/False: The statement Set Cost = Price + Tax is an example of a comparison statement.
4. True/False: The statement 15 >= -63 will result in the value True.
5. True/False: If X = False and Y = False, is the statement:
NOT X OR NOT Y
True or False?
6. True/False: Suppose MyNumber = 6. Is the following expression True or False?
(2 * MyNumber – 4 > 6 ) AND (MyNumber < 10)
- True/False: If A = 20 and B = 15, then both of the following statements are True:
A > B and B <= A
8. True/False: The type of operators that are evaluated second in the hierarchy of order of operations are logical operators.
9. True/False: The Case statement cannot be used to compare numeric data.
10. True/False: The integer 16 does not have a reciprocal.
11. True/False: If a division operation is performed in a program and the divisor is 0, execution will halt and an error message will be displayed.
12. True/False: Defensive programming includes checking for the illegal operation of trying to take the square root of zero.
13. True/False: A program that uses menus instead of requiring the user to memorize commands is often known as a menu-driven program.
14. True/False: If A = 9, then Sqrt(A * A) = 3.
15. True/False: In an If-Then-Else selection structure, at least one line of code will always be skipped.
16. True/False: A test condition in a conditional statement checks to see if a statement is True or False.
- True/False: The following two pairs of statements produce the same result:
a. | b. |
If X is true AND Y is true Then do Z Else do W | If X is NOT true OR Y is NOT true Then do W Else do Z |
18. True/False: 95 <= 94
19. True/False: “Joan” <= “Jane”
20. True/False: Given that X = 14 and Y = 15, is the following true or false?
X > Y OR X > 0 AND Y < 0
SHORT ANSWER
1. A selection structure consists of a(n) __________ __________ together with one or more blocks of statements.
2. A statement which checks to see if the value of the expression on the left side is the same as the value of the expression on the right side is an example of the use of the __________ operator.
3. Two strings are __________ if they contain exactly the same characters in the same order.
4. A(n) __________ __________ is used to summarize the actions of the logical operators.
5. Logical operators are used to create __________ conditions from given __________ conditions.
6. In the hierarchy of the order of operations (relational, logical, arithmetic), __________ operations are performed last.
7. Some programming languages allow variables to be of logical or __________ type.
8. The >= is one of the __________ operators.
9. The multiple-alternative selection structure that does not use an If-Then-Else clause is the __________ or __________ statement.
10. Including statements in a program to check for improper data during execution of the program is known as __________ programming.
11. The program segment that catches a possible by zero is known as a(n) __________ __________.
12. One type of “illegal operation” is an attempt to take the square root of a(n) ___________ __________.
13. The reciprocal of 0 is __________.
14. The order of operations for __________ __________ is NOT first, then AND, then OR.
15. A dual-alternative selection structure is also known as a(n) __________ structure.