Deck 3: Making Decisions

Full screen (f)
exit full mode
Question
It is a common mistake to use = instead of ____.

A) ||
B) &&
C) ==
D) !=
Use Space or
up arrow
down arrow
to flip the card.
Question
Consider the following segment of code:
Char genderCode;
Cout > genderCode;
If(genderCode == 'F')
Cout
What will appear on the screen if the user enters 'M'?

A) "Female"
B) "Male"
C) "Invalid code"
D) ""
Question
You must always surround a single statement after an if with curly braces.
Question
Almost every C++ expression has a numeric value, and any C++ expression can be evaluated as part of an if statement.
Question
The Boolean expression used in an if statement is often a comparison, such as "x greater than y," but in C++ it can also be a number or a(n) ____.

A) arithmetic expression
B) logical expression
C) character
D) relational expression
Question
Consider the following segment of code:
If(vacationDays = 0)
Cout
What error can you identify?

A) The code assumes indentation has a logical purpose.
B) A semicolon is incorrectly inserted.
C) There are no curly braces.
D) An assignment operator is used in a comparison.
Question
An else must always be associated with an if , and vice versa.
Question
Consider the following segment of code:
If (driverAge
What error can you identify?

A) The code makes unnecessary comparisons.
B) A semicolon is incorrectly inserted.
C) There are no curly braces.
D) The programmer did not take into account that C++ is case sensitive.
Question
Consider the following segment of code:
If(vacationDays = 0)
Cout
What will be the output on screen if vacationDays is 0?

A) "No vacation days available"
B) "You have vacation days coming"
C) ""
D) Nothing, because the code will not compile.
Question
The ____ surrounding the evaluated expression in an if statement are essential.

A) curly braces
B) angle brackets
C) parentheses
D) square brackets
Question
Consider the following C++ code:
If(driverAge 50)
PremiumDue -= 50;
If(numTickets == 2)
PremiumDue += 60.25;
How much is added to premiumDue if driverAge is 22 and numTickets is 0 ?

A) -50
B) 10.25
C) 60.25
D) 100
Question
Consider the following segment of code:
If(testScore >= HIGH_GRADE)
Cout = MED_GRADE)
Cout
What error can you identify?

A) The code assumes indentation has a logical purpose.
B) A semicolon is incorrectly inserted.
C) The programmer did not use curly braces.
D) The segment contains unreachable code.
Question
In C++, ____ has/have no logical purpose.

A) indentation
B) semicolons
C) curly braces
D) parentheses
Question
In C++, any value other than 0, even a negative value, is considered to be true.
Question
The ____, although not as flexible as the if statement, is useful when a single variable must be compared to multiple values.

A) else statement
B) switch statement
C) case statement
D) conditional operator ( ? )
Question
When writing C++ blocks of code, the compiler ignores any indentations you make; only curly braces can indicate which statements are performed as a block.
Question
Consider the following segment of code:
If (driverAge
What error can you identify?

A) The code assumes indentation has a logical purpose.
B) A semicolon is incorrectly inserted.
C) There are no curly braces.
D) The programmer did not take into account that C++ is case sensitive.
Question
Consider the following segment of code:
If(-5) cout
What will be the output on screen?

A) "OK"
B) "Cancel"
C) ""
D) Nothing, because the code will not compile.
Question
Programmers often write the if statement on two lines to visually separate the decision-making condition from its resulting action; however, only one ____ follows the entire statement.

A) parenthesis
B) curly brace
C) colon
D) semicolon
Question
The ____ takes one action when its Boolean expression is evaluated as true, and uses an else clause to define the actions to take when the expression is evaluated as false.

A) dual-alternative if
B) single-alternative if
C) switch statement
D) conditional operator
Question
What is an advantage of using the conditional operator?
Question
Consider the following code segment:
if (driverAge
What is the purpose of the curly braces?
Question
Each case in a switch statement can be followed by any number of statements to execute. Unlike with the if statement, the statements to be executed do not need to be contained in a block with ____________________.
Question
With ____ evaluations, parts of an AND expression are evaluated only as far as necessary to determine whether the entire expression is true or false .

A) conditional
B) short-circuit
C) nested
D) dead logical path
Question
Consider the following example of a switch statement:
switch(department)
{
case 1:
cout
What happens if you remove the break statements from the code?
Question
A single-alternative selection is one in which an action takes place only when the result of the decision is ____________________.
Question
A struct definition always ends with a(n) ____ following the closing curly brace.

A) colon
B) semicolon
C) ampersand
D) square bracket
Question
Is the conditional operator used frequently? Why or why not?
Question
As with an if , you can also ____________________ multiple statements in the else portion of an if statement.
Question
Mention at least four mistakes that are easy to make when you are first learning to use selection statements.
Question
The conditional operator is an example of a(n) ____ operator.

A) unary
B) binary
C) ternary
D) assignment
Question
Use a logical OR to write a more concise equivalent of the following code:
if(saleAmount >= 300)
cout
Question
When does the following code display "Yes"?
If(department == 1 || 2)
Cout

A) When department is 1
B) When department is 1 or 2
C) Always
D) Never
Question
If the expression in an if statement is evaluated as anything other than 0, it is considered to be ____________________.
Question
Consider the following segment of code:
If(driverAge
The same logic can be expressed using the conditional operator as follows: ____

A) driverAge
B) driverAge
C) driverAge
D) driverAge
Question
C++ comparisons are ____________________ sensitive.
Question
Use a logical AND to write a more concise equivalent of the following code:
if(numVisits > 5)
if(annualSpent >= 1000)
cout
Question
Consider the following example of a switch statement:
switch(department)
{
case 1:
cout
When does the default option execute?
Question
The conditional operator is also called the ____ operator.

A) if
B) else
C) if-else
D) question
Question
Write an example of a nested if-else statement.
Question
Match between columns
created by typing two pipes
nested if
created by typing two pipes
dual-alternative if
created by typing two pipes
switch statement
created by typing two pipes
if-else-if
created by typing two pipes
logical AND
created by typing two pipes
dead logical path
created by typing two pipes
logical OR
created by typing two pipes
single-alternative if
created by typing two pipes
conditional operator
Question
Match between columns
created by typing two ampersands
nested if
created by typing two ampersands
dual-alternative if
created by typing two ampersands
switch statement
created by typing two ampersands
if-else-if
created by typing two ampersands
logical AND
created by typing two ampersands
dead logical path
created by typing two ampersands
logical OR
created by typing two ampersands
single-alternative if
created by typing two ampersands
conditional operator
Question
Match between columns
represented by a question mark
nested if
represented by a question mark
dual-alternative if
represented by a question mark
switch statement
represented by a question mark
if-else-if
represented by a question mark
logical AND
represented by a question mark
dead logical path
represented by a question mark
logical OR
represented by a question mark
single-alternative if
represented by a question mark
conditional operator
Question
When using a logical AND (or a logical OR), are the expressions to both sides of the && (or || ) always evaluated? Explain.
Question
Match between columns
an alternative to a series of if statements
nested if
an alternative to a series of if statements
dual-alternative if
an alternative to a series of if statements
switch statement
an alternative to a series of if statements
if-else-if
an alternative to a series of if statements
logical AND
an alternative to a series of if statements
dead logical path
an alternative to a series of if statements
logical OR
an alternative to a series of if statements
single-alternative if
an alternative to a series of if statements
conditional operator
Question
Match between columns
contains unreachable code
nested if
contains unreachable code
dual-alternative if
contains unreachable code
switch statement
contains unreachable code
if-else-if
contains unreachable code
logical AND
contains unreachable code
dead logical path
contains unreachable code
logical OR
contains unreachable code
single-alternative if
contains unreachable code
conditional operator
Question
Match between columns
structure in which a new decision rests within the else clause of another decision
nested if
structure in which a new decision rests within the else clause of another decision
dual-alternative if
structure in which a new decision rests within the else clause of another decision
switch statement
structure in which a new decision rests within the else clause of another decision
if-else-if
structure in which a new decision rests within the else clause of another decision
logical AND
structure in which a new decision rests within the else clause of another decision
dead logical path
structure in which a new decision rests within the else clause of another decision
logical OR
structure in which a new decision rests within the else clause of another decision
single-alternative if
structure in which a new decision rests within the else clause of another decision
conditional operator
Question
Match between columns
if structure that rests entirely within another if structure
nested if
if structure that rests entirely within another if structure
dual-alternative if
if structure that rests entirely within another if structure
switch statement
if structure that rests entirely within another if structure
if-else-if
if structure that rests entirely within another if structure
logical AND
if structure that rests entirely within another if structure
dead logical path
if structure that rests entirely within another if structure
logical OR
if structure that rests entirely within another if structure
single-alternative if
if structure that rests entirely within another if structure
conditional operator
Question
Match between columns
also called the if-else structure
nested if
also called the if-else structure
dual-alternative if
also called the if-else structure
switch statement
also called the if-else structure
if-else-if
also called the if-else structure
logical AND
also called the if-else structure
dead logical path
also called the if-else structure
logical OR
also called the if-else structure
single-alternative if
also called the if-else structure
conditional operator
Question
Match between columns
an action takes place only when the result of the decision is true
nested if
an action takes place only when the result of the decision is true
dual-alternative if
an action takes place only when the result of the decision is true
switch statement
an action takes place only when the result of the decision is true
if-else-if
an action takes place only when the result of the decision is true
logical AND
an action takes place only when the result of the decision is true
dead logical path
an action takes place only when the result of the decision is true
logical OR
an action takes place only when the result of the decision is true
single-alternative if
an action takes place only when the result of the decision is true
conditional operator
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 3: Making Decisions
1
It is a common mistake to use = instead of ____.

A) ||
B) &&
C) ==
D) !=
C
2
Consider the following segment of code:
Char genderCode;
Cout > genderCode;
If(genderCode == 'F')
Cout
What will appear on the screen if the user enters 'M'?

A) "Female"
B) "Male"
C) "Invalid code"
D) ""
B
3
You must always surround a single statement after an if with curly braces.
False
4
Almost every C++ expression has a numeric value, and any C++ expression can be evaluated as part of an if statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
The Boolean expression used in an if statement is often a comparison, such as "x greater than y," but in C++ it can also be a number or a(n) ____.

A) arithmetic expression
B) logical expression
C) character
D) relational expression
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
Consider the following segment of code:
If(vacationDays = 0)
Cout
What error can you identify?

A) The code assumes indentation has a logical purpose.
B) A semicolon is incorrectly inserted.
C) There are no curly braces.
D) An assignment operator is used in a comparison.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
An else must always be associated with an if , and vice versa.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
Consider the following segment of code:
If (driverAge
What error can you identify?

A) The code makes unnecessary comparisons.
B) A semicolon is incorrectly inserted.
C) There are no curly braces.
D) The programmer did not take into account that C++ is case sensitive.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
Consider the following segment of code:
If(vacationDays = 0)
Cout
What will be the output on screen if vacationDays is 0?

A) "No vacation days available"
B) "You have vacation days coming"
C) ""
D) Nothing, because the code will not compile.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
The ____ surrounding the evaluated expression in an if statement are essential.

A) curly braces
B) angle brackets
C) parentheses
D) square brackets
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
Consider the following C++ code:
If(driverAge 50)
PremiumDue -= 50;
If(numTickets == 2)
PremiumDue += 60.25;
How much is added to premiumDue if driverAge is 22 and numTickets is 0 ?

A) -50
B) 10.25
C) 60.25
D) 100
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
Consider the following segment of code:
If(testScore >= HIGH_GRADE)
Cout = MED_GRADE)
Cout
What error can you identify?

A) The code assumes indentation has a logical purpose.
B) A semicolon is incorrectly inserted.
C) The programmer did not use curly braces.
D) The segment contains unreachable code.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
In C++, ____ has/have no logical purpose.

A) indentation
B) semicolons
C) curly braces
D) parentheses
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
In C++, any value other than 0, even a negative value, is considered to be true.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
The ____, although not as flexible as the if statement, is useful when a single variable must be compared to multiple values.

A) else statement
B) switch statement
C) case statement
D) conditional operator ( ? )
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
When writing C++ blocks of code, the compiler ignores any indentations you make; only curly braces can indicate which statements are performed as a block.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
Consider the following segment of code:
If (driverAge
What error can you identify?

A) The code assumes indentation has a logical purpose.
B) A semicolon is incorrectly inserted.
C) There are no curly braces.
D) The programmer did not take into account that C++ is case sensitive.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
Consider the following segment of code:
If(-5) cout
What will be the output on screen?

A) "OK"
B) "Cancel"
C) ""
D) Nothing, because the code will not compile.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
Programmers often write the if statement on two lines to visually separate the decision-making condition from its resulting action; however, only one ____ follows the entire statement.

A) parenthesis
B) curly brace
C) colon
D) semicolon
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
The ____ takes one action when its Boolean expression is evaluated as true, and uses an else clause to define the actions to take when the expression is evaluated as false.

A) dual-alternative if
B) single-alternative if
C) switch statement
D) conditional operator
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
What is an advantage of using the conditional operator?
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
Consider the following code segment:
if (driverAge
What is the purpose of the curly braces?
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
Each case in a switch statement can be followed by any number of statements to execute. Unlike with the if statement, the statements to be executed do not need to be contained in a block with ____________________.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
With ____ evaluations, parts of an AND expression are evaluated only as far as necessary to determine whether the entire expression is true or false .

A) conditional
B) short-circuit
C) nested
D) dead logical path
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
Consider the following example of a switch statement:
switch(department)
{
case 1:
cout
What happens if you remove the break statements from the code?
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
A single-alternative selection is one in which an action takes place only when the result of the decision is ____________________.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
A struct definition always ends with a(n) ____ following the closing curly brace.

A) colon
B) semicolon
C) ampersand
D) square bracket
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
Is the conditional operator used frequently? Why or why not?
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
As with an if , you can also ____________________ multiple statements in the else portion of an if statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
Mention at least four mistakes that are easy to make when you are first learning to use selection statements.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
The conditional operator is an example of a(n) ____ operator.

A) unary
B) binary
C) ternary
D) assignment
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
Use a logical OR to write a more concise equivalent of the following code:
if(saleAmount >= 300)
cout
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
When does the following code display "Yes"?
If(department == 1 || 2)
Cout

A) When department is 1
B) When department is 1 or 2
C) Always
D) Never
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
If the expression in an if statement is evaluated as anything other than 0, it is considered to be ____________________.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
Consider the following segment of code:
If(driverAge
The same logic can be expressed using the conditional operator as follows: ____

A) driverAge
B) driverAge
C) driverAge
D) driverAge
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
C++ comparisons are ____________________ sensitive.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
Use a logical AND to write a more concise equivalent of the following code:
if(numVisits > 5)
if(annualSpent >= 1000)
cout
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
Consider the following example of a switch statement:
switch(department)
{
case 1:
cout
When does the default option execute?
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
The conditional operator is also called the ____ operator.

A) if
B) else
C) if-else
D) question
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
Write an example of a nested if-else statement.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
Match between columns
created by typing two pipes
nested if
created by typing two pipes
dual-alternative if
created by typing two pipes
switch statement
created by typing two pipes
if-else-if
created by typing two pipes
logical AND
created by typing two pipes
dead logical path
created by typing two pipes
logical OR
created by typing two pipes
single-alternative if
created by typing two pipes
conditional operator
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
Match between columns
created by typing two ampersands
nested if
created by typing two ampersands
dual-alternative if
created by typing two ampersands
switch statement
created by typing two ampersands
if-else-if
created by typing two ampersands
logical AND
created by typing two ampersands
dead logical path
created by typing two ampersands
logical OR
created by typing two ampersands
single-alternative if
created by typing two ampersands
conditional operator
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
Match between columns
represented by a question mark
nested if
represented by a question mark
dual-alternative if
represented by a question mark
switch statement
represented by a question mark
if-else-if
represented by a question mark
logical AND
represented by a question mark
dead logical path
represented by a question mark
logical OR
represented by a question mark
single-alternative if
represented by a question mark
conditional operator
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
When using a logical AND (or a logical OR), are the expressions to both sides of the && (or || ) always evaluated? Explain.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
Match between columns
an alternative to a series of if statements
nested if
an alternative to a series of if statements
dual-alternative if
an alternative to a series of if statements
switch statement
an alternative to a series of if statements
if-else-if
an alternative to a series of if statements
logical AND
an alternative to a series of if statements
dead logical path
an alternative to a series of if statements
logical OR
an alternative to a series of if statements
single-alternative if
an alternative to a series of if statements
conditional operator
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
Match between columns
contains unreachable code
nested if
contains unreachable code
dual-alternative if
contains unreachable code
switch statement
contains unreachable code
if-else-if
contains unreachable code
logical AND
contains unreachable code
dead logical path
contains unreachable code
logical OR
contains unreachable code
single-alternative if
contains unreachable code
conditional operator
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
Match between columns
structure in which a new decision rests within the else clause of another decision
nested if
structure in which a new decision rests within the else clause of another decision
dual-alternative if
structure in which a new decision rests within the else clause of another decision
switch statement
structure in which a new decision rests within the else clause of another decision
if-else-if
structure in which a new decision rests within the else clause of another decision
logical AND
structure in which a new decision rests within the else clause of another decision
dead logical path
structure in which a new decision rests within the else clause of another decision
logical OR
structure in which a new decision rests within the else clause of another decision
single-alternative if
structure in which a new decision rests within the else clause of another decision
conditional operator
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
Match between columns
if structure that rests entirely within another if structure
nested if
if structure that rests entirely within another if structure
dual-alternative if
if structure that rests entirely within another if structure
switch statement
if structure that rests entirely within another if structure
if-else-if
if structure that rests entirely within another if structure
logical AND
if structure that rests entirely within another if structure
dead logical path
if structure that rests entirely within another if structure
logical OR
if structure that rests entirely within another if structure
single-alternative if
if structure that rests entirely within another if structure
conditional operator
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
Match between columns
also called the if-else structure
nested if
also called the if-else structure
dual-alternative if
also called the if-else structure
switch statement
also called the if-else structure
if-else-if
also called the if-else structure
logical AND
also called the if-else structure
dead logical path
also called the if-else structure
logical OR
also called the if-else structure
single-alternative if
also called the if-else structure
conditional operator
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
Match between columns
an action takes place only when the result of the decision is true
nested if
an action takes place only when the result of the decision is true
dual-alternative if
an action takes place only when the result of the decision is true
switch statement
an action takes place only when the result of the decision is true
if-else-if
an action takes place only when the result of the decision is true
logical AND
an action takes place only when the result of the decision is true
dead logical path
an action takes place only when the result of the decision is true
logical OR
an action takes place only when the result of the decision is true
single-alternative if
an action takes place only when the result of the decision is true
conditional operator
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 50 flashcards in this deck.