Deck 5: The Selection Structure
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
Play
Full screen (f)
Deck 5: The Selection Structure
1
The word "if" is the foundation of the selection structure.
True
2
With a selection structure, your program can choose between alternate courses of action.
True
3
A selection structure allows you to teach the computer how to make decisions.
True
4
In many programming languages the relational operator for testing whether two values are equal is <=.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
In pseudocode, a dual-outcome selection consists of three parts:
• The word If, the condition expression, and the word Then
• The statement or statements to be performed if the condition is true; indented for readability
• The words End If lined up under the word If
• The word If, the condition expression, and the word Then
• The statement or statements to be performed if the condition is true; indented for readability
• The words End If lined up under the word If
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
When creating a flowchart to represent selection structures, you use the rectangular symbol for a condition expression.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
On a flowchart, the End If statement in pseudocode is represented by the square connector symbol.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
On a flowchart, a question mark at the end of the expression emphasizes that the condition must be evaluated.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9

-The flowchart segment in the accompanying figure depicts a dual-outcome selection that tests the value of the number of correct items.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
Structures can contain other structures, and they can be contained in other structures. They can also overlap.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
Pseudocode uses indentation and the keywords End If to define the scope.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
You should put a semicolon after the condition in a selection structure.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
In JavaScript, braces ({ }) are used to define the scope of a selection structure's true and false branches.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
You should use braces for all selection structures, even if the scope of the true or false branch consists of only one statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
Selections can be nested inside other selections.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
Nested selections, when written formally, require indentations for each new Else statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
Programs with several levels of nesting can be hard to follow.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
JavaScript allows using the keywords else if together and does not require nested braces around nested structures.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
In some languages, including JavaScript, the Case structure can test only for equality of values, not inequalities using ranges of numbers.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
A Case structure is limited in most languages to integers (whole numbers), text characters and decimal numbers.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
In a JavaScript, the entire Case structure is enclosed in a set of braces. However, the scope for each condition does not have to be enclosed in a separate set of braces.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
The end command, which is an exception to structured programming principles, is the most efficient way to exit a Case structure.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
A Case structure is used most often when conditions are treated separately.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
The selection structure and its variations with Else If statements and Case structures are among the most powerful tools a programmer has.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
The following statement concatenates a customer's name:
custName = firstName + " " + lastName
custName = firstName + " " + lastName
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
A ____ structure evaluates a condition, which is an expression that's true or false.
A) repetition
B) Case
C) sequence
D) selection
A) repetition
B) Case
C) sequence
D) selection
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
A selection structure depends on a(n) ____, an expression describing the relationship between two values that's evaluated when it appears in program code.
A) condition
B) variable
C) index
D) sentinel
A) condition
B) variable
C) index
D) sentinel
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
A ____ evaluates to a true or false value.
A) sentinel
B) condition
C) Boolean expression
D) selection structure
A) sentinel
B) condition
C) Boolean expression
D) selection structure
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
The following symbols are known as ____.
<, >, ==, <=, >=, !=
A) sentinels
B) relational operators
C) selection structures
D) assignment statements
<, >, ==, <=, >=, !=
A) sentinels
B) relational operators
C) selection structures
D) assignment statements
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
The simplest selection structure is one in which an action is taken if the condition evaluates to true, but no action is taken if the condition evaluates to false. This structure is called the ____.
A) single-outcome selection
B) dual-outcome selection
C) nested sequence
D) nested selection
A) single-outcome selection
B) dual-outcome selection
C) nested sequence
D) nested selection
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following statements corresponds to the question below?
Is the value of hours greater than 40?
A) hours < 40
B) hours >= 40
C) hours > 40
D) hours == 40
Is the value of hours greater than 40?
A) hours < 40
B) hours >= 40
C) hours > 40
D) hours == 40
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
Which of the following statements corresponds to the question below?
Is the value of status not equal to "denied"?
A) status == "denied"
B) status != "denied"
C) status >= "denied"
D) status !== "denied"
Is the value of status not equal to "denied"?
A) status == "denied"
B) status != "denied"
C) status >= "denied"
D) status !== "denied"
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
Which of the following statements corresponds to the question below?
Is the value of grade greater than or equal to 90?
A) grade > 90
B) grade <= 90
C) grade >= 90
D) grade != 90
Is the value of grade greater than or equal to 90?
A) grade > 90
B) grade <= 90
C) grade >= 90
D) grade != 90
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
Which of the following is an example of a single-outcome selection?
A) If testScore >= 60 Then
Display "That is a passing grade."
Else
Display "That is a failing grade."
End If
B) If hoursWorked > 40 Then
OvertimeHours = hoursWorked - 40
OvertimePay = overtimeHours * wageRate * 1.5
RegularPay = 40 * wageRate
GrossPay = regularPay + overtimePay
Else
GrossPay = hoursWorked * wageRate
End If
C) If age >= 65 Then
DiscountRate = 0.10
End If
D) Method deposit(Numeric amt)
AcctBal = acctBal + amt
Display "The new balance is: $" + acctBal
End Method
A) If testScore >= 60 Then
Display "That is a passing grade."
Else
Display "That is a failing grade."
End If
B) If hoursWorked > 40 Then
OvertimeHours = hoursWorked - 40
OvertimePay = overtimeHours * wageRate * 1.5
RegularPay = 40 * wageRate
GrossPay = regularPay + overtimePay
Else
GrossPay = hoursWorked * wageRate
End If
C) If age >= 65 Then
DiscountRate = 0.10
End If
D) Method deposit(Numeric amt)
AcctBal = acctBal + amt
Display "The new balance is: $" + acctBal
End Method
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
The code for the following is ____.
"If the value of password is not bottomsUp, display the message Access denied.":
A) If password ! "bottomsUp" Then
Display "Access denied."
End If
B) If password !== "bottomsUp" Then
Display "Access denied."
End If
C) If password >= "bottomsUp" Then
Display "Access denied."
End If
D) If password != "bottomsUp" Then
Display "Access denied."
End If
"If the value of password is not bottomsUp, display the message Access denied.":
A) If password ! "bottomsUp" Then
Display "Access denied."
End If
B) If password !== "bottomsUp" Then
Display "Access denied."
End If
C) If password >= "bottomsUp" Then
Display "Access denied."
End If
D) If password != "bottomsUp" Then
Display "Access denied."
End If
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
The code for the following is ____.
"If the value of numCorrect is equal to 3, set bonusPoints to 10 and display the message Congratulations! You win 10 bonus points."
A) If numCorrect == 3 Then
BonusPoints = 10
Display "Congratulations! You win 10 bonus points."
End If
B) If numCorrect <= 3 Then
BonusPoints == 10
Display "Congratulations! You win 10 bonus points."
End If
C) If numCorrect > 3 Then
BonusPoints == 10
Display "Congratulations! You win 10 bonus points."
End If
D) If numCorrect != 3 Then
BonusPoints == 10
Display "Congratulations! You win 10 bonus points."
End If
"If the value of numCorrect is equal to 3, set bonusPoints to 10 and display the message Congratulations! You win 10 bonus points."
A) If numCorrect == 3 Then
BonusPoints = 10
Display "Congratulations! You win 10 bonus points."
End If
B) If numCorrect <= 3 Then
BonusPoints == 10
Display "Congratulations! You win 10 bonus points."
End If
C) If numCorrect > 3 Then
BonusPoints == 10
Display "Congratulations! You win 10 bonus points."
End If
D) If numCorrect != 3 Then
BonusPoints == 10
Display "Congratulations! You win 10 bonus points."
End If
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37

-The flowchart segment in the accompanying figure depicts a ____.
A) sequence structure contained in a repetition structure
B) dual-outcome selection structure
C) repetition structure
D) single-outcome selection structure
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
Which of the following programs displays a "passing grade" message if the score is 60 or above?
A) Display "Enter a test score: "
Input testScore
If testScore > 60 Then
Display "That is a passing grade."
End If
Display "End of program."
B) Display "Enter a test score: " Input testScoreIf
TestScore ==60 Then
Display "That is a passing grade."
End If
Display "End of program."
C) Display "Enter a test score: " Input testScoreIf
TestScore <=60 Then
Display "That is a passing grade."
End If
Display "End of program."
D) Display "Enter a test score: " Input testScoreIf
TestScore >=60 Then
Display "That is a passing grade."
End If
Display "End of program."
A) Display "Enter a test score: "
Input testScore
If testScore > 60 Then
Display "That is a passing grade."
End If
Display "End of program."
B) Display "Enter a test score: " Input testScoreIf
TestScore ==60 Then
Display "That is a passing grade."
End If
Display "End of program."
C) Display "Enter a test score: " Input testScoreIf
TestScore <=60 Then
Display "That is a passing grade."
End If
Display "End of program."
D) Display "Enter a test score: " Input testScoreIf
TestScore >=60 Then
Display "That is a passing grade."
End If
Display "End of program."
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39

-The flowchart in the accompanying figure depicts a ____.
A) repetition structure.
B) sequence structure contained in a repetition structure
C) selection structure contained in a sequence structure.
D) dual-outcome selection with multiple actions.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
A ____ performs one set of steps if the condition is true and a different set of steps if the condition is false.
A) dual-outcome selection
B) repetition structure
C) single-outcome selection
D) sequence structure
A) dual-outcome selection
B) repetition structure
C) single-outcome selection
D) sequence structure
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41

-The following flowchart is an example of a ____.
A) repetition structure
B) dual-outcome selection
C) sequence structure
D) single-outcome selection
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42

-The flowchart in the accompanying figure depicts a ____.
A) dual-outcome selection with multiple actions
B) dual-outcome selection
C) selection structure contained in a sequence structure.
D) single-outcome selection
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
The JavaScript code for the following algorithm is ____.
If age >= 65 Then
DiscountRate = 0.10
End If
A) if (age >= 65) Then { discountRate == 0.10;} end if
B) if (age >= 65) {discountRate == 0.10} end if
C) if (age >= 65) Then {discountRate = 0.10;}
D) if (age >= 65) {discountRate = 0.10;}
If age >= 65 Then
DiscountRate = 0.10
End If
A) if (age >= 65) Then { discountRate == 0.10;} end if
B) if (age >= 65) {discountRate == 0.10} end if
C) if (age >= 65) Then {discountRate = 0.10;}
D) if (age >= 65) {discountRate = 0.10;}
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
A selection contained in the scope of another selection is called a ____.
A) nested selection
B) sequence structure
C) single outcome selection
D) repetition structure
A) nested selection
B) sequence structure
C) single outcome selection
D) repetition structure
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
The pseudocode for the following problem is ____.
Suppose all students in grade 12 at a high school are to be selected for a field trip, but the boys are leaving on the 8:30 a.m. bus and the girls are leaving at 9:00 a.m.
A) If gradeLevel == 12 Then
Display "Enter M for male, or F for female: "
If gender == "M" Then
Display "Your bus leaves at 8:30 a.m."
Else If
Display "Your bus leaves at 9:00 a.m."
End If
End If
B) If gradeLevel == 12; Display "Enter M for male, or F for female: "
If gender == "M" Then;
Display "Your bus leaves at 8:30 a.m."
Else;
Display "Your bus leaves at 9:00 a.m."
End If;
End If
C) If gradeLevel == 12 Then Display "Enter M for male, or F for female: "
Input gender
If gender == "M" Then
Display "Your bus leaves at 8:30 a.m."
Else
Display "Your bus leaves at 9:00 a.m."
End If
End If
D) If gradeLevel >= 12 Then Display "Enter M for male, or F for female: "
If gender == "M"
Display "Your bus leaves at 8:30 a.m."
Else
Display "Your bus leaves at 9:00 a.m."
End
End If
Suppose all students in grade 12 at a high school are to be selected for a field trip, but the boys are leaving on the 8:30 a.m. bus and the girls are leaving at 9:00 a.m.
A) If gradeLevel == 12 Then
Display "Enter M for male, or F for female: "
If gender == "M" Then
Display "Your bus leaves at 8:30 a.m."
Else If
Display "Your bus leaves at 9:00 a.m."
End If
End If
B) If gradeLevel == 12; Display "Enter M for male, or F for female: "
If gender == "M" Then;
Display "Your bus leaves at 8:30 a.m."
Else;
Display "Your bus leaves at 9:00 a.m."
End If;
End If
C) If gradeLevel == 12 Then Display "Enter M for male, or F for female: "
Input gender
If gender == "M" Then
Display "Your bus leaves at 8:30 a.m."
Else
Display "Your bus leaves at 9:00 a.m."
End If
End If
D) If gradeLevel >= 12 Then Display "Enter M for male, or F for female: "
If gender == "M"
Display "Your bus leaves at 8:30 a.m."
Else
Display "Your bus leaves at 9:00 a.m."
End
End If
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
Based on the grading scale below, what is the most efficient way of determining a grade?
• A if the grade percentage is greater than or equal to 90
• B if it's greater than or equal to 80 and less than 90
• C if it's greater than or equal to 70 and less than 80
• D if it's greater than or equal to 60 and less than 70
• F if the grade percentage is less than 60
A) Test each condition separately.
B) Test the score for a value between 80 and 90 only if the first condition is false.
C) Test to see whether the percentage is 90 or higher.
D) Test to see whether the percentage is less than 60.
• A if the grade percentage is greater than or equal to 90
• B if it's greater than or equal to 80 and less than 90
• C if it's greater than or equal to 70 and less than 80
• D if it's greater than or equal to 60 and less than 70
• F if the grade percentage is less than 60
A) Test each condition separately.
B) Test the score for a value between 80 and 90 only if the first condition is false.
C) Test to see whether the percentage is 90 or higher.
D) Test to see whether the percentage is less than 60.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
For nested selections that test the same variable for different values, developers created the ____, which is actually a variation of the selection structure.
A) Case structure
B) dual outcome structure
C) If structure
D) For structure
A) Case structure
B) dual outcome structure
C) If structure
D) For structure
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
A(n) ____ structure starts with the pseudocode keyword Select, followed by the name of the variable to test for equality with a variety of values, and ends with a colon.
A) If
B) single-outcome
C) Case
D) dual-outcome
A) If
B) single-outcome
C) Case
D) dual-outcome
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49

-The flowchart in the accompanying figure depicts a ____.
A) single-outcome selection
B) Case structure
C) dual-outcome selection
D) if structure
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
In JavaScript, a Case structure starts with the keyword ____, and the name of the variable to test is enclosed in parentheses.
A) Case
B) begin
C) switch
D) select
A) Case
B) begin
C) switch
D) select
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck