Deck 3: Making Decisions
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
Match between columns
Question
Match between columns
Question
Match between columns
Question
Question
Match between columns
Question
Match between columns
Question
Match between columns
Question
Match between columns
Question
Match between columns
Question
Match between columns
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
Play
Full screen (f)
Deck 3: Making Decisions
1
It is a common mistake to use = instead of ____.
A) ||
B) &&
C) ==
D) !=
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) ""
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
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.
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.
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.
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
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
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.
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
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 ( ? )
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.
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.
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
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
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?
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
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?
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
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
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
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
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
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
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?
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
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
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
Match between columns
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
Match between columns
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
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
Match between columns
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
Match between columns
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
Match between columns
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
Match between columns
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
Match between columns
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck