Deck 15: 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
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/40
Play
Full screen (f)
Deck 15: Making Decisions
1
In a switch statement, what keyword is followed by one of the possible values that might equal the switch expression?
A) case
B) default
C) break
D) switch
A) case
B) default
C) break
D) switch
A
2
You can combine as many AND and OR operators in an expression as needed.
True
3
What character(s) function as the non-conditional Boolean logical inclusive OR operator?
A) |
B) &&
C) &
D) ||
A) |
B) &&
C) &
D) ||
A
4
In a situation where you want to perform one action when a Boolean expression evaluates as true and an alternate action when it evaluates as false, otherwise known as a dual-alternative decision, what sort of statement should you use?
A) if-else
B) if
C) switch
D) fork
A) if-else
B) if
C) switch
D) fork
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
5
What character(s) function as the conditional OR operator in the C# programming language?
A) &
B) |
C) &&
D) ||
A) &
B) |
C) &&
D) ||
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
6
When creating a flowchart or pseudocode representation of a task, what type of structure is one in which one step follows another unconditionally?
A) single-decision
B) dual-decision
C) branched
D) sequence
A) single-decision
B) dual-decision
C) branched
D) sequence
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
7
What character(s) function as the non-conditional Boolean logical AND operator in the C# programming language?
A) &&
B) |
C) &
D) ||
A) &&
B) |
C) &
D) ||
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
8
What sort of evaluation involves the evaluation of expressions in each part of a compound, conditional Boolean expression only as much as necessary to determine whether the expression is false?
A) sequential
B) sequence
C) smart
D) short-circuit
A) sequential
B) sequence
C) smart
D) short-circuit
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
9
What should you use if you wish to execute two or more statements conditionally?
A) A switch statement.
B) A block enclosed within a pair of curly braces.
C) A defined sequence structure.
D) A declared decision structure.
A) A switch statement.
B) A block enclosed within a pair of curly braces.
C) A defined sequence structure.
D) A declared decision structure.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
10
When using a switch structure to make decisions within a program, what keyword is used to begin the structure?
A) if
B) case
C) break
D) switch
A) if
B) case
C) break
D) switch
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
11
What type of statement can be used to make a single-alternative decision?
A) switch
B) fork
C) if
D) if-else
A) switch
B) fork
C) if
D) if-else
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
12
What conditional operator can be used when you want some action to occur even if only one of two given conditions is true?
A) AND
B) OR
C) XOR
D) NOT
A) AND
B) OR
C) XOR
D) NOT
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
13
Flowchart creators use diamond shapes to indicate alternative courses of action.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
14
It is illegal to use a block to contain a single statement.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
15
When if-else statements are nested, each else is always paired with the most recent unpaired if.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
16
What type of structure involves choosing between alternative courses of action based on some value within a program?
A) decision
B) sequence
C) literal
D) fixed
A) decision
B) sequence
C) literal
D) fixed
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
17
What character(s) do you use to make a conditional AND operator within a C# program?
A) ||
B) |
C) &&
D) &
A) ||
B) |
C) &&
D) &
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
18
What conditional operator can be used to create a compound Boolean expression as an alternative to if statements?
A) OR
B) AND
C) XOR
D) NOT
A) OR
B) AND
C) XOR
D) NOT
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
19
In a switch statement, the keyword return usually terminates each case.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
20
The if expression that precedes a block in a decision structure is known as what type of statement?
A) sequence
B) conditional
C) K & R
D) control
A) sequence
B) conditional
C) K & R
D) control
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
21
What character(s) serve as the NOT operator in the C# programming language?
A) &
B) &&
C) <>
D) !
A) &
B) &&
C) <>
D) !
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
22
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;
if(salesCode != 'A' || salesCode != 'B')
discount = 0.10;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
23
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?
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 40 flashcards in this deck.
Unlock Deck
k this deck
24
What kind of conditional operator requires three arguments: a test expression, and true and false result expressions?
A) binary conditional operator
B) ternary conditional operator
C) unary conditional operator
D) enumeration conditional operator
A) binary conditional operator
B) ternary conditional operator
C) unary conditional operator
D) enumeration conditional operator
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
25
What is the syntax of the conditional operator? Describe how the operator is used.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
26
What can be used in conjunction with a switch statement in order to make the meaning of case label values much clearer?
A) if structure
B) OR
C) enumeration
D) conditional AND
A) if structure
B) OR
C) enumeration
D) conditional AND
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
27
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 40 flashcards in this deck.
Unlock Deck
k this deck
28
What rule results in an error if you reach the end point of a statement list in a case section?
A) no fall through
B) en passant
C) break on end
D) default
A) no fall through
B) en passant
C) break on end
D) default
Unlock Deck
Unlock for access to all 40 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 40 flashcards in this deck.
Unlock Deck
k this deck
30
List the four keywords used in a switch structure and provide a brief description of each.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
31
When the & and | operators are used between Boolean expressions, they are Boolean logical operators.What are they when used between integer expressions?
A) integral operators
B) numerical operators
C) bitwise operators
D) arithmetic operators
A) integral operators
B) numerical operators
C) bitwise operators
D) arithmetic operators
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
32
When designing a flowchart for assisting in the coding process, what is a parallelogram typically used to represent?
A) They usually represent errors that should occur when provided invalid data.
B) They usually represent a declaration of a value.
C) They usually represent decision blocks.
D) They usually represent input and output statements.
A) They usually represent errors that should occur when provided invalid data.
B) They usually represent a declaration of a value.
C) They usually represent decision blocks.
D) They usually represent input and output statements.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
33
Explain (in words) how bonuses are assigned in the following example:
if(saleAmount > 1000)
if(saleAmount < 2000)
bonus = 100;
else
bonus = 50;
if(saleAmount > 1000)
if(saleAmount < 2000)
bonus = 100;
else
bonus = 50;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
34
Why are all computer decisions true-or-false decisions?
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
35
Placing the opening brace of an if block on the same line as the if statement is known as what style of programming?
A) K & R style
B) Allman style
C) GNU style
D) Haskell style
A) K & R style
B) Allman style
C) GNU style
D) Haskell style
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
36
What character(s) are used to form the ternary conditional operator in C#?
A) ?:
B) ?;
C) !:
D) ?
A) ?:
B) ?;
C) !:
D) ?
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
37
What keyword can you use to specify an action to take in the event that a test expression does not match any case?
A) break
B) switch
C) default
D) else
A) break
B) switch
C) default
D) else
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
38
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 <= 499)
commissionRate = 0.05;
if (saleAmount >= 1000)
commissionRate = 0.08;
else if (saleAmount >= 500)
commissionRate = 0.06;
else if (saleAmount <= 499)
commissionRate = 0.05;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
39
In C#, what operator is used as an abbreviated version of the if-else statement, and requires three expressions separated with a question mark and a colon?
A) switch
B) NOT
C) conditional
D) XOR
A) switch
B) NOT
C) conditional
D) XOR
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
40
Describe how short-circuit evaluation works when evaluating compound Boolean expressions.Show an example.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck