Deck 4: 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 4: Making Decisions
1
The C++ ________ operator represents logical AND.
A) ++
B) )AND.
C) ||
D) &
E) &&
A) ++
B) )AND.
C) ||
D) &
E) &&
E
2
Relational operators allow you to ________ numbers.
A) add
B) multiply
C) compare
D) average
E) verify
A) add
B) multiply
C) compare
D) average
E) verify
C
3
Which of the following correctly declares an enumerated data type named student?
A) enum student { Bill, Tom, Mary };
B) enum student { "Bill", "Tom", "Mary" };
C) int Bill = 1, Tom = 2, Mary = 3; enum student { 1, 2, 3 };
D) Any of the above 3 methods will work.
E) None of the above 3 methods will work.
A) enum student { Bill, Tom, Mary };
B) enum student { "Bill", "Tom", "Mary" };
C) int Bill = 1, Tom = 2, Mary = 3; enum student { 1, 2, 3 };
D) Any of the above 3 methods will work.
E) None of the above 3 methods will work.
A
4
To check if a variable has a particular value, use the = relational operator, as in the statement
if (s = 3)
cout << "S has the value 3";
if (s = 3)
cout << "S has the value 3";
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
5
Assuming goodData is a Boolean variable, the following two tests are logically equivalent.
if (goodData == false)
if (!goodData)
if (goodData == false)
if (!goodData)
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
6
In C++ when a relational expression is false, it has the value
A) 1.
B) 0.
C) -1.
D) "0".
E) of any negative number.
A) 1.
B) 0.
C) -1.
D) "0".
E) of any negative number.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
7
The ________ statement executes one block of statements if a test condition is True, and another block if the condition is false.
A) if
B) if/else
C) if/else if
D) switch
E) trailing else
A) if
B) if/else
C) if/else if
D) switch
E) trailing else
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
8
A pair of characters or a pair of string objects can be compared with any of the relational operators.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
9
All of the relational operators are binary.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
10
logical operators AND and OR have a higher precedence than the NOT operator.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
11
The ________ operator takes an operand and reverses its truth or falsehood.
A) relational
B) &&
C) ||
D) !
E) !=
A) relational
B) &&
C) ||
D) !
E) !=
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
12
If the sub-expression on the left side of an || operator is True, the expression on the right side will not be checked.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
13
A(n) ________ is a variable, usually a bool, that signals when a condition exists.
A) flag
B) identifier
C) named constant
D) condition variable
E) logical variable
A) flag
B) identifier
C) named constant
D) condition variable
E) logical variable
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
14
If a switch statement has no ________ statements, the program "falls through" all of the statements below the one with the matching case expression.
A) break
B) exit
C) case
D) default
E) relational
A) break
B) exit
C) case
D) default
E) relational
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
15
A trailing else placed at the end of an if/else if statement provides a default action when ________ of the if conditions is/are True.
A) none
B) any one
C) only the last one
D) at least two
E) all
A) none
B) any one
C) only the last one
D) at least two
E) all
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
16
The statement
pass = (score >= 7) ?
True : false;
does exactly the same thing as the if/else statement below:
if (score >= 7)
pass = True;
else
pass = false;
pass = (score >= 7) ?
True : false;
does exactly the same thing as the if/else statement below:
if (score >= 7)
pass = True;
else
pass = false;
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
17
The rule for matching an else with an if is that an else goes with the last if statement before it that doesn't have its own else.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
18
When an if statement is placed within the conditionally-executed code of another if statement, this is known as a(n)
A) complex if
B) overloaded if
C) nested if
D) conditional if
E) double if
A) complex if
B) overloaded if
C) nested if
D) conditional if
E) double if
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
19
The ________ statement causes other program statements to execute only under certain conditions.
A) logical
B) relational
C) cin
D) cout
E) if
A) logical
B) relational
C) cin
D) cout
E) if
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
20
The following C++ test checks if the variable child is in the range 3 to 12.
if (child >= 3 || child <= 12)
if (child >= 3 || child <= 12)
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
21
The ________ operator is used in C++ to test for equality.
A) =
B) <>
C) &&
D) ==
E) ||
A) =
B) <>
C) &&
D) ==
E) ||
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
22
Assuming moreData is a Boolean variable, the following two tests are logically equivalent.
if (moreData == True)
if (moreData)
if (moreData == True)
if (moreData)
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
23
A flag is a variable, usually of data type ________, that signals whether or not some condition exists.
A) char
B) string
C) int
D) bool
E) logical
A) char
B) string
C) int
D) bool
E) logical
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
24
The following C++ test checks if the variable child is in the range 3 - 12.
if (child >= 3 && <= 12)
if (child >= 3 && <= 12)
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
25
What will the following statement do if x equals 17 and answer = 20?
Answer = x > 100 ?
0 : 1;
A) Assign 0 to answer.
B) Assign 0 to x.
C) Assign 1 to answer.
D) Assign 1 to x.
E) Assign 17 to answer.
Answer = x > 100 ?
0 : 1;
A) Assign 0 to answer.
B) Assign 0 to x.
C) Assign 1 to answer.
D) Assign 1 to x.
E) Assign 17 to answer.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
26
The default section of a switch statement performs a similar task as the ________ portion of an if/else if statement.
A) conditional test
B) break
C) trailing else
D) else if
E) body
A) conditional test
B) break
C) trailing else
D) else if
E) body
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
27
If s1 and s2 are string objects, s1 == s2 is True when
A) s1 = "lion" and s2 = "lioness".
B) s1 = "dog" and s2 = "DOG".
C) s1 = "cat" and s2 = "cat ".
D) None of these because in each case one or more characters in the strings have different ASCII codes.
E) None of these because string objects cannot be compared with relational operators.
A) s1 = "lion" and s2 = "lioness".
B) s1 = "dog" and s2 = "DOG".
C) s1 = "cat" and s2 = "cat ".
D) None of these because in each case one or more characters in the strings have different ASCII codes.
E) None of these because string objects cannot be compared with relational operators.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
28
When a program lets the user know that an invalid menu choice has been made, this is an example of
A) input validation.
B) output validation.
C) menu reselection.
D) invalidation.
E) being user unfriendly.
A) input validation.
B) output validation.
C) menu reselection.
D) invalidation.
E) being user unfriendly.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
29
The scope of a variable is the program it is defined in.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
30
The ________ statement acts like a chain of if statements. Each performs its test, one after the other, until one of them is found to be True or until the construct is exited without any test ever evaluating to True.
A) if/then
B) if/else
C) if/else if
D) if/not if
E) if/endif
A) if/then
B) if/else
C) if/else if
D) if/not if
E) if/endif
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
31
The expression x < y is called a(n) ________ expression.
A) arithmetic
B) logical
C) relational
D) comparison
E) binary
A) arithmetic
B) logical
C) relational
D) comparison
E) binary
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
32
Relational operators connect two or more relational expressions into one, or reverse the logic of an expression.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
33
The following statements will not print anything.
x = 5;
if (x < 5)
cout << "Hello ";
cout << "world \n";
x = 5;
if (x < 5)
cout << "Hello ";
cout << "world \n";
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
34
What will the following expression evaluate to?
!( 6 > 7 || 3 == 4)
A) 0
B) -1
C) 6
D) True
E) false
!( 6 > 7 || 3 == 4)
A) 0
B) -1
C) 6
D) True
E) false
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
35
The ________ statement executes one statement, or block of statements, if a condition is True and skips it, doing nothing, if the condition is false.
A) if
B) if/else
C) if/else if
D) switch
E) if/endif
A) if
B) if/else
C) if/else if
D) switch
E) if/endif
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
36
The ________ operator is known as the logical OR operator.
A) !
B) &
C) &&
D) ||
E) //
A) !
B) &
C) &&
D) ||
E) //
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
37
A switch statement branches to a particular block of code depending on the value of a numeric (i.e. integer or floating-point) variable or constant.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
38
If the sub-expression on the left side of an && operator is True, the expression on the right side will not be checked.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
39
Relational expressions and logical expressions are both Boolean, which means they evaluate to True or false.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
40
An expression in a C++ if statement that evaluates to 5, -5, or for that matter anything other than 0, is considered True.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck