Deck 4: Making Decisions

Full screen (f)
exit full mode
Question
It is illegal to use a block to contain a single statement.
Use Space or
up arrow
down arrow
to flip the card.
Question
The non-conditional Boolean logical inclusive OR operator is written as ____.

A) |
B) &&
C) &
D) ||
Question
In a decision structure, the if expression that precedes a block is called the ____ statement.

A) sequence
B) conditional
C) K & R
D) control
Question
Flowchart creators use diamond shapes to indicate alternative courses of action.
Question
In C#, a ____ is a collection of one or more statements contained within a pair of curly braces.

A) switch
B) block
C) sequence structure
D) decision structure
Question
You can use the conditional ____ operator when you want some action to occur even if only one of two conditions is true .

A) AND
B) OR
C) XOR
D) NOT
Question
In a switch statement, the keyword ____ starts the switch structure.

A) if
B) case
C) break
D) switch
Question
A(n) ____ statement is used to make a single-alternative decision.

A) switch
B) fork
C) if
D) if-else
Question
You can use the conditional ____ operator within a Boolean expression to determine whether two expressions are both true .

A) OR
B) AND
C) XOR
D) NOT
Question
The non-conditional Boolean logical AND operator is written as ____.

A) &&
B) |
C) &
D) ||
Question
The expressions in each part of a compound, conditional Boolean expression are evaluated only as much as necessary to determine whether the entire expression is true or false . This feature is called ____ evaluation.

A) sequential
B) sequence
C) smart
D) short-circuit
Question
When if-else statements are nested, each else is always paired with the most recent unpaired if .
Question
A ____ structure involves choosing between alternative courses of action based on some value within a program.

A) decision
B) sequence
C) literal
D) fixed
Question
You can combine as many AND and OR operators in an expression as needed.
Question
The conditional AND operator is written as ____.

A) ||
B) |
C) &&
D) &
Question
The conditional OR operator is written as ____.

A) &
B) |
C) &&
D) ||
Question
In a switch statement, the keyword return usually terminates each case.
Question
When creating a flowchart or pseudocode representation of a task, a ____ structure is one in which one step follows another unconditionally.

A) single-decision
B) dual-decision
C) branched
D) sequence
Question
If you have a dual-alternative decision (you want to perform one action when a Boolean expression evaluates as true and an alternate action when it evaluates as false ), you can use a(n) ____ statement.

A) if-else
B) if
C) switch
D) fork
Question
In a switch statement, the keyword ____ is followed by one of the possible values that might equal the switch expression.

A) case
B) default
C) break
D) switch
Question
Using a(n) ____ with a switch statement can often be convenient because it can make the meaning of case label values much clearer.

A) if structure
B) OR
C) enumeration
D) conditional AND
Question
In a switch statement, the type of the value in a case label is the ____________________ type.
Question
A(n) ____________________ is similar to pseudocode, but you write the steps in diagram form, as a series of shapes connected by arrows.
Question
Why are all computer decisions true-or-false decisions?
Question
Explain why the following code sample does not capture the intent of the request "Make sure if the sales code is not 'A' or 'B', the customer gets a 10% discount". What is the correct if statement?
if (salesCode != 'A' || salesCode != 'B')
discount = 0.10;
Question
Describe how short-circuit evaluation works when evaluating compound Boolean expressions. Show an example.
Question
The ____________________ structure, an alternative to nested if statements, tests a single variable against a series of exact matches.
Question
In C#, the ____ operator is used as an abbreviated version of the if-else statement.

A) switch
B) NOT
C) conditional
D) XOR
Question
What is the difference between the conditional AND and OR operators and their logical counterparts? How can incorrect use of the logical operators lead to unintended consequences in your program?
Question
Explain (in words) how bonuses are assigned in the following example:
if (saleAmount > 1000)
if (saleAmount
bonus = 100;
else
bonus = 50;
Question
The optional keyword ____ is used prior to any action that should occur if the test expression does not match any case.

A) break
B) switch
C) default
D) else
Question
List the four keywords used in a switch structure and provide a brief description of each.
Question
Programmers often use ____________________, a tool that helps them plan a program's logic by writing plain English statements.
Question
What are four of the most frequent errors new programmers make when they first learn to make decisions?
Question
The following range-checking code works but is somewhat inefficient. Explain why and show how to revise it to be more efficient.
if (saleAmount >= 1000)
commissionRate = 0.08;
else if (saleAmount >= 500)
commissionRate = 0.06;
else if (saleAmount
commissionRate = 0.05;
Question
A(n) ____________________ decision has two possible resulting actions.
Question
In C#, an error occurs if you reach the end point of the statement list in a case section. This is known as the ____ rule.

A) no fall through
B) en passant
C) break on end
D) default
Question
What is the syntax of the conditional operator? Describe how the operator is used.
Question
The conditional operator ?: is a(n) ____ operator.

A) binary
B) ternary
C) unary
D) enumeration
Question
The NOT operator is written as ____.

A) &
B) &&
C) $
D) !
Question
Match between columns
Negates the result of any Boolean expression
side effect
Negates the result of any Boolean expression
switch expression
Negates the result of any Boolean expression
conditional operator
Negates the result of any Boolean expression
nested if
Negates the result of any Boolean expression
range check
Negates the result of any Boolean expression
case label
Negates the result of any Boolean expression
enumeration
Negates the result of any Boolean expression
NOT operator
Negates the result of any Boolean expression
truth table
Identifies a course of action in a switch structure
side effect
Identifies a course of action in a switch structure
switch expression
Identifies a course of action in a switch structure
conditional operator
Identifies a course of action in a switch structure
nested if
Identifies a course of action in a switch structure
range check
Identifies a course of action in a switch structure
case label
Identifies a course of action in a switch structure
enumeration
Identifies a course of action in a switch structure
NOT operator
Identifies a course of action in a switch structure
truth table
A statement in which one decision structure is contained within another
side effect
A statement in which one decision structure is contained within another
switch expression
A statement in which one decision structure is contained within another
conditional operator
A statement in which one decision structure is contained within another
nested if
A statement in which one decision structure is contained within another
range check
A statement in which one decision structure is contained within another
case label
A statement in which one decision structure is contained within another
enumeration
A statement in which one decision structure is contained within another
NOT operator
A statement in which one decision structure is contained within another
truth table
A diagram used to describe the Boolean value of an entire compound expression
side effect
A diagram used to describe the Boolean value of an entire compound expression
switch expression
A diagram used to describe the Boolean value of an entire compound expression
conditional operator
A diagram used to describe the Boolean value of an entire compound expression
nested if
A diagram used to describe the Boolean value of an entire compound expression
range check
A diagram used to describe the Boolean value of an entire compound expression
case label
A diagram used to describe the Boolean value of an entire compound expression
enumeration
A diagram used to describe the Boolean value of an entire compound expression
NOT operator
A diagram used to describe the Boolean value of an entire compound expression
truth table
The only ternary operator in C#
side effect
The only ternary operator in C#
switch expression
The only ternary operator in C#
conditional operator
The only ternary operator in C#
nested if
The only ternary operator in C#
range check
The only ternary operator in C#
case label
The only ternary operator in C#
enumeration
The only ternary operator in C#
NOT operator
The only ternary operator in C#
truth table
A series of if statements that determine whether a value falls within a specified range
side effect
A series of if statements that determine whether a value falls within a specified range
switch expression
A series of if statements that determine whether a value falls within a specified range
conditional operator
A series of if statements that determine whether a value falls within a specified range
nested if
A series of if statements that determine whether a value falls within a specified range
range check
A series of if statements that determine whether a value falls within a specified range
case label
A series of if statements that determine whether a value falls within a specified range
enumeration
A series of if statements that determine whether a value falls within a specified range
NOT operator
A series of if statements that determine whether a value falls within a specified range
truth table
An unintended consequence
side effect
An unintended consequence
switch expression
An unintended consequence
conditional operator
An unintended consequence
nested if
An unintended consequence
range check
An unintended consequence
case label
An unintended consequence
enumeration
An unintended consequence
NOT operator
An unintended consequence
truth table
Allows you to assign values to a list of constants
side effect
Allows you to assign values to a list of constants
switch expression
Allows you to assign values to a list of constants
conditional operator
Allows you to assign values to a list of constants
nested if
Allows you to assign values to a list of constants
range check
Allows you to assign values to a list of constants
case label
Allows you to assign values to a list of constants
enumeration
Allows you to assign values to a list of constants
NOT operator
Allows you to assign values to a list of constants
truth table
A test expression in a switch structure
side effect
A test expression in a switch structure
switch expression
A test expression in a switch structure
conditional operator
A test expression in a switch structure
nested if
A test expression in a switch structure
range check
A test expression in a switch structure
case label
A test expression in a switch structure
enumeration
A test expression in a switch structure
NOT operator
A test expression in a switch structure
truth table
Question
You write a program in which the user must select whether to receive instructions in English or Spanish. In a console application, you would issue the prompt:
Which language do you prefer? Enter 1 for English or 2 for Spanish >>
The program would accept the user's entry, make a decision, and take appropriate action. How would you commonly handle this decision-making situation in a GUI application?
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/42
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 4: Making Decisions
1
It is illegal to use a block to contain a single statement.
False
2
The non-conditional Boolean logical inclusive OR operator is written as ____.

A) |
B) &&
C) &
D) ||
A
3
In a decision structure, the if expression that precedes a block is called the ____ statement.

A) sequence
B) conditional
C) K & R
D) control
D
4
Flowchart creators use diamond shapes to indicate alternative courses of action.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
5
In C#, a ____ is a collection of one or more statements contained within a pair of curly braces.

A) switch
B) block
C) sequence structure
D) decision structure
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
6
You can use the conditional ____ operator when you want some action to occur even if only one of two conditions is true .

A) AND
B) OR
C) XOR
D) NOT
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
7
In a switch statement, the keyword ____ starts the switch structure.

A) if
B) case
C) break
D) switch
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
8
A(n) ____ statement is used to make a single-alternative decision.

A) switch
B) fork
C) if
D) if-else
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
9
You can use the conditional ____ operator within a Boolean expression to determine whether two expressions are both true .

A) OR
B) AND
C) XOR
D) NOT
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
10
The non-conditional Boolean logical AND operator is written as ____.

A) &&
B) |
C) &
D) ||
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
11
The expressions in each part of a compound, conditional Boolean expression are evaluated only as much as necessary to determine whether the entire expression is true or false . This feature is called ____ evaluation.

A) sequential
B) sequence
C) smart
D) short-circuit
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
12
When if-else statements are nested, each else is always paired with the most recent unpaired if .
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
13
A ____ structure involves choosing between alternative courses of action based on some value within a program.

A) decision
B) sequence
C) literal
D) fixed
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
14
You can combine as many AND and OR operators in an expression as needed.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
15
The conditional AND operator is written as ____.

A) ||
B) |
C) &&
D) &
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
16
The conditional OR operator is written as ____.

A) &
B) |
C) &&
D) ||
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
17
In a switch statement, the keyword return usually terminates each case.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
18
When creating a flowchart or pseudocode representation of a task, a ____ structure is one in which one step follows another unconditionally.

A) single-decision
B) dual-decision
C) branched
D) sequence
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
19
If you have a dual-alternative decision (you want to perform one action when a Boolean expression evaluates as true and an alternate action when it evaluates as false ), you can use a(n) ____ statement.

A) if-else
B) if
C) switch
D) fork
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
20
In a switch statement, the keyword ____ is followed by one of the possible values that might equal the switch expression.

A) case
B) default
C) break
D) switch
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
21
Using a(n) ____ with a switch statement can often be convenient because it can make the meaning of case label values much clearer.

A) if structure
B) OR
C) enumeration
D) conditional AND
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
22
In a switch statement, the type of the value in a case label is the ____________________ type.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
23
A(n) ____________________ is similar to pseudocode, but you write the steps in diagram form, as a series of shapes connected by arrows.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
24
Why are all computer decisions true-or-false decisions?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
25
Explain why the following code sample does not capture the intent of the request "Make sure if the sales code is not 'A' or 'B', the customer gets a 10% discount". What is the correct if statement?
if (salesCode != 'A' || salesCode != 'B')
discount = 0.10;
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
26
Describe how short-circuit evaluation works when evaluating compound Boolean expressions. Show an example.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
27
The ____________________ structure, an alternative to nested if statements, tests a single variable against a series of exact matches.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
28
In C#, the ____ operator is used as an abbreviated version of the if-else statement.

A) switch
B) NOT
C) conditional
D) XOR
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
29
What is the difference between the conditional AND and OR operators and their logical counterparts? How can incorrect use of the logical operators lead to unintended consequences in your program?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
30
Explain (in words) how bonuses are assigned in the following example:
if (saleAmount > 1000)
if (saleAmount
bonus = 100;
else
bonus = 50;
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
31
The optional keyword ____ is used prior to any action that should occur if the test expression does not match any case.

A) break
B) switch
C) default
D) else
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
32
List the four keywords used in a switch structure and provide a brief description of each.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
33
Programmers often use ____________________, a tool that helps them plan a program's logic by writing plain English statements.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
34
What are four of the most frequent errors new programmers make when they first learn to make decisions?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
35
The following range-checking code works but is somewhat inefficient. Explain why and show how to revise it to be more efficient.
if (saleAmount >= 1000)
commissionRate = 0.08;
else if (saleAmount >= 500)
commissionRate = 0.06;
else if (saleAmount
commissionRate = 0.05;
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
36
A(n) ____________________ decision has two possible resulting actions.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
37
In C#, an error occurs if you reach the end point of the statement list in a case section. This is known as the ____ rule.

A) no fall through
B) en passant
C) break on end
D) default
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
38
What is the syntax of the conditional operator? Describe how the operator is used.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
39
The conditional operator ?: is a(n) ____ operator.

A) binary
B) ternary
C) unary
D) enumeration
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
40
The NOT operator is written as ____.

A) &
B) &&
C) $
D) !
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
41
Match between columns
Negates the result of any Boolean expression
side effect
Negates the result of any Boolean expression
switch expression
Negates the result of any Boolean expression
conditional operator
Negates the result of any Boolean expression
nested if
Negates the result of any Boolean expression
range check
Negates the result of any Boolean expression
case label
Negates the result of any Boolean expression
enumeration
Negates the result of any Boolean expression
NOT operator
Negates the result of any Boolean expression
truth table
Identifies a course of action in a switch structure
side effect
Identifies a course of action in a switch structure
switch expression
Identifies a course of action in a switch structure
conditional operator
Identifies a course of action in a switch structure
nested if
Identifies a course of action in a switch structure
range check
Identifies a course of action in a switch structure
case label
Identifies a course of action in a switch structure
enumeration
Identifies a course of action in a switch structure
NOT operator
Identifies a course of action in a switch structure
truth table
A statement in which one decision structure is contained within another
side effect
A statement in which one decision structure is contained within another
switch expression
A statement in which one decision structure is contained within another
conditional operator
A statement in which one decision structure is contained within another
nested if
A statement in which one decision structure is contained within another
range check
A statement in which one decision structure is contained within another
case label
A statement in which one decision structure is contained within another
enumeration
A statement in which one decision structure is contained within another
NOT operator
A statement in which one decision structure is contained within another
truth table
A diagram used to describe the Boolean value of an entire compound expression
side effect
A diagram used to describe the Boolean value of an entire compound expression
switch expression
A diagram used to describe the Boolean value of an entire compound expression
conditional operator
A diagram used to describe the Boolean value of an entire compound expression
nested if
A diagram used to describe the Boolean value of an entire compound expression
range check
A diagram used to describe the Boolean value of an entire compound expression
case label
A diagram used to describe the Boolean value of an entire compound expression
enumeration
A diagram used to describe the Boolean value of an entire compound expression
NOT operator
A diagram used to describe the Boolean value of an entire compound expression
truth table
The only ternary operator in C#
side effect
The only ternary operator in C#
switch expression
The only ternary operator in C#
conditional operator
The only ternary operator in C#
nested if
The only ternary operator in C#
range check
The only ternary operator in C#
case label
The only ternary operator in C#
enumeration
The only ternary operator in C#
NOT operator
The only ternary operator in C#
truth table
A series of if statements that determine whether a value falls within a specified range
side effect
A series of if statements that determine whether a value falls within a specified range
switch expression
A series of if statements that determine whether a value falls within a specified range
conditional operator
A series of if statements that determine whether a value falls within a specified range
nested if
A series of if statements that determine whether a value falls within a specified range
range check
A series of if statements that determine whether a value falls within a specified range
case label
A series of if statements that determine whether a value falls within a specified range
enumeration
A series of if statements that determine whether a value falls within a specified range
NOT operator
A series of if statements that determine whether a value falls within a specified range
truth table
An unintended consequence
side effect
An unintended consequence
switch expression
An unintended consequence
conditional operator
An unintended consequence
nested if
An unintended consequence
range check
An unintended consequence
case label
An unintended consequence
enumeration
An unintended consequence
NOT operator
An unintended consequence
truth table
Allows you to assign values to a list of constants
side effect
Allows you to assign values to a list of constants
switch expression
Allows you to assign values to a list of constants
conditional operator
Allows you to assign values to a list of constants
nested if
Allows you to assign values to a list of constants
range check
Allows you to assign values to a list of constants
case label
Allows you to assign values to a list of constants
enumeration
Allows you to assign values to a list of constants
NOT operator
Allows you to assign values to a list of constants
truth table
A test expression in a switch structure
side effect
A test expression in a switch structure
switch expression
A test expression in a switch structure
conditional operator
A test expression in a switch structure
nested if
A test expression in a switch structure
range check
A test expression in a switch structure
case label
A test expression in a switch structure
enumeration
A test expression in a switch structure
NOT operator
A test expression in a switch structure
truth table
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
42
You write a program in which the user must select whether to receive instructions in English or Spanish. In a console application, you would issue the prompt:
Which language do you prefer? Enter 1 for English or 2 for Spanish >>
The program would accept the user's entry, make a decision, and take appropriate action. How would you commonly handle this decision-making situation in a GUI application?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 42 flashcards in this deck.