Deck 4: Making Decisions

Full screen (f)
exit full mode
Question
The operator takes an operand and reverses its truth or falsehood.

A)&&
B)!
C)relational
D)!=
E)||
Use Space or
up arrow
down arrow
to flip the card.
Question
A flag is a variable, usually of data type , that signals whether or not some condition exists.

A)logical
B)string
C)char
D)bool
E)int
Question
Two different variables in the same program may have the same name

A)if they always hold different values.
B)if the second one is never declared.
C)if they have different scope.
D)if the second one is initialized with a different value than the first one.
E)never. A program cannot have two variables with the same name.
Question
Relational operators allow you to numbers.

A)average
B)verify
C)add
D)compare
E)multiply
Question
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)switch
C)if/else
D)if/endif
E)if/else if
Question
When an if statement is placed within the conditionally- executed code of another if statement, this is known as a(n)

A)overloaded if
B)conditional if
C)complex if
D)double if
E)nested if
Question
The expression x < y is called a(n)expression.

A)logical
B)relational
C)binary
D)arithmetic
E)comparison
Question
A(n)is a variable, usually a bool, that signals when a condition exists.

A)identifier
B)named constant
C)condition variable
D)logical variable
E)flag
Question
In C++ when a relational expression is false, it has the value
A)"0".

A)1.
B)0.
D)- 1.
E)of any negative number.
Question
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.

A)if/then
B)if/endif
C)if/else if
D)if/not if
E)if/else
Question
If s1 and s2 are string objects, s1 == s2 is true when

A)s1 = "cat" and s2 = "cat ".
B)s1 = "lion" and s2 = "lioness".
C)s1 = "dog" and s2 = "DOG".
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.
Question
If a switch statement has no statements, the program "falls through" all of the statements below the one with the matching case expression.

A)relational
B)break
C)default
D)exit
E)case
Question
The statement executes one block of statements if a test condition is true, and another block if the condition is false.

A)if/else if
B)trailing else
C)if/else
D)switch
E)if
Question
What will the following expression evaluate to? <strong>What will the following expression evaluate to?  </strong> A)0 B)6 C)-1 D)true E)false <div style=padding-top: 35px>

A)0
B)6
C)-1
D)true
E)false
Question
What will the following statement do if x equals 17 and answer = 20? answer = x > 100 ? 0 : 1;

A)Assign 0 to x.
B)Assign 17 to answer.
C)Assign 1 to answer.
D)Assign 0 to answer.
E)Assign 1 to x.
Question
The statement causes other program statements to execute only under certain conditions.

A)logical
B)cout
C)cin
D)if
E)relational
Question
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)all
C)any one
D)only the last one
E)at least two
Question
The default section of a switch statement performs a similar task as the portion of an if/else if statement.

A)conditional test
B)trailing else
C)else if
D)break
E)body
Question
Which of the following correctly declares an enumerated data type named student?

A)enum student { "Bill", "Tom", "Mary" };
B)int Bill = 1, Tom = 2, Mary = 3; enum student { 1, 2, 3 };
C)enum student { Bill, Tom, Mary };
D)Any of the above 3 methods will work.
E)None of the above 3 methods will work.
Question
When a program lets the user know that an invalid menu choice has been made, this is an example of

A)being user unfriendly.
B)input validation.
C)invalidation.
D)output validation.
E)menu reselection.
Question
If the sub- expression on the left side of an || operator is true, the expression on the right side will not be checked.
Question
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.
Question
All of the relational operators are binary.
Question
A pair of characters or a pair of string objects can be compared with any of the relational operators.
Question
The following C++ test checks if the variable child is in the range 3- 12.
The following C++ test checks if the variable child is in the range 3- 12.  <div style=padding-top: 35px>
Question
The three logical operators, AND, OR, and NOT, all have the same precedence.
Question
The statement
The statement  <div style=padding-top: 35px>
Question
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.
Question
To check if a variable has a particular value, use the = relational operator, as in the statement
To check if a variable has a particular value, use the = relational operator, as in the statement  <div style=padding-top: 35px>
Question
Relational expressions and logical expressions are both Boolean, which means they evaluate to true or false.
Question
The following C++ test checks if the variable child is in the range 3-12.
The following C++ test checks if the variable child is in the range 3-12.  <div style=padding-top: 35px>
Question
The following statement s will not print anything.
The following statement s will not print anything.  <div style=padding-top: 35px>
Question
If the sub- expression on the left side of an && operator is true, the expression on the right side will not be checked.
Question
Assuming moreData is a Boolean variable, the following two tests are logically equivalent.
Assuming moreData is a Boolean variable, the following two tests are logically equivalent.  <div style=padding-top: 35px>
Question
In C++ an expression that evaluates to 5, - 5, or for that matter anything other than 0, is considered true by an if statement.
Question
Relational operators connect two or more relational expressions into one, or reverse the logic of an expression.
Question
Assuming goodData is a Boolean variable, the following two tests are logically equivalent.
Assuming goodData is a Boolean variable, the following two tests are logically equivalent.  <div style=padding-top: 35px>
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/37
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 4: Making Decisions
1
The operator takes an operand and reverses its truth or falsehood.

A)&&
B)!
C)relational
D)!=
E)||
B
2
A flag is a variable, usually of data type , that signals whether or not some condition exists.

A)logical
B)string
C)char
D)bool
E)int
D
3
Two different variables in the same program may have the same name

A)if they always hold different values.
B)if the second one is never declared.
C)if they have different scope.
D)if the second one is initialized with a different value than the first one.
E)never. A program cannot have two variables with the same name.
C
4
Relational operators allow you to numbers.

A)average
B)verify
C)add
D)compare
E)multiply
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
5
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)switch
C)if/else
D)if/endif
E)if/else if
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
6
When an if statement is placed within the conditionally- executed code of another if statement, this is known as a(n)

A)overloaded if
B)conditional if
C)complex if
D)double if
E)nested if
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
7
The expression x < y is called a(n)expression.

A)logical
B)relational
C)binary
D)arithmetic
E)comparison
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
8
A(n)is a variable, usually a bool, that signals when a condition exists.

A)identifier
B)named constant
C)condition variable
D)logical variable
E)flag
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
9
In C++ when a relational expression is false, it has the value
A)"0".

A)1.
B)0.
D)- 1.
E)of any negative number.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
10
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.

A)if/then
B)if/endif
C)if/else if
D)if/not if
E)if/else
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
11
If s1 and s2 are string objects, s1 == s2 is true when

A)s1 = "cat" and s2 = "cat ".
B)s1 = "lion" and s2 = "lioness".
C)s1 = "dog" and s2 = "DOG".
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 37 flashcards in this deck.
Unlock Deck
k this deck
12
If a switch statement has no statements, the program "falls through" all of the statements below the one with the matching case expression.

A)relational
B)break
C)default
D)exit
E)case
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
13
The statement executes one block of statements if a test condition is true, and another block if the condition is false.

A)if/else if
B)trailing else
C)if/else
D)switch
E)if
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
14
What will the following expression evaluate to? <strong>What will the following expression evaluate to?  </strong> A)0 B)6 C)-1 D)true E)false

A)0
B)6
C)-1
D)true
E)false
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
15
What will the following statement do if x equals 17 and answer = 20? answer = x > 100 ? 0 : 1;

A)Assign 0 to x.
B)Assign 17 to answer.
C)Assign 1 to answer.
D)Assign 0 to answer.
E)Assign 1 to x.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
16
The statement causes other program statements to execute only under certain conditions.

A)logical
B)cout
C)cin
D)if
E)relational
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
17
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)all
C)any one
D)only the last one
E)at least two
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
18
The default section of a switch statement performs a similar task as the portion of an if/else if statement.

A)conditional test
B)trailing else
C)else if
D)break
E)body
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
19
Which of the following correctly declares an enumerated data type named student?

A)enum student { "Bill", "Tom", "Mary" };
B)int Bill = 1, Tom = 2, Mary = 3; enum student { 1, 2, 3 };
C)enum student { Bill, Tom, Mary };
D)Any of the above 3 methods will work.
E)None of the above 3 methods will work.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
20
When a program lets the user know that an invalid menu choice has been made, this is an example of

A)being user unfriendly.
B)input validation.
C)invalidation.
D)output validation.
E)menu reselection.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
21
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 37 flashcards in this deck.
Unlock Deck
k this deck
22
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 37 flashcards in this deck.
Unlock Deck
k this deck
23
All of the relational operators are binary.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
24
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 37 flashcards in this deck.
Unlock Deck
k this deck
25
The following C++ test checks if the variable child is in the range 3- 12.
The following C++ test checks if the variable child is in the range 3- 12.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
26
The three logical operators, AND, OR, and NOT, all have the same precedence.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
27
The statement
The statement
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
28
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 37 flashcards in this deck.
Unlock Deck
k this deck
29
To check if a variable has a particular value, use the = relational operator, as in the statement
To check if a variable has a particular value, use the = relational operator, as in the statement
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
30
Relational expressions and logical expressions are both Boolean, which means they evaluate to true or false.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
31
The following C++ test checks if the variable child is in the range 3-12.
The following C++ test checks if the variable child is in the range 3-12.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
32
The following statement s will not print anything.
The following statement s will not print anything.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
33
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 37 flashcards in this deck.
Unlock Deck
k this deck
34
Assuming moreData is a Boolean variable, the following two tests are logically equivalent.
Assuming moreData is a Boolean variable, the following two tests are logically equivalent.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
35
In C++ an expression that evaluates to 5, - 5, or for that matter anything other than 0, is considered true by an if statement.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
36
Relational operators connect two or more relational expressions into one, or reverse the logic of an expression.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
37
Assuming goodData is a Boolean variable, the following two tests are logically equivalent.
Assuming goodData is a Boolean variable, the following two tests are logically equivalent.
Unlock Deck
Unlock for access to all 37 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 37 flashcards in this deck.