C++ Ch4 Study Guide
The ________ operator takes an operand and reverses its truth or falsehood.
!
The C++ ________ operator represents logical AND.
&&
In C++ when a relational expression is false, it has the value
0
The ________ operator is used in C++ to test for equality.
==
If a switch statement has no ________ statements, the program "falls through" all of the statements below the one with the matching case expression.
Break
True/False: If the sub-expression on the left side of an && operator is true, the expression on the right side will not be checked.
False
True/False: Relational operators connect two or more relational expressions into one, or reverse the logic of an expression.
False
True/False: The following C++ test checks if the variable child is in the range 3 to 12.if (child >= 3 || child <= 12)
False
True/False: 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";
False
True/False: logical operators AND and OR have a higher precedence than the NOT operator.
False
A(n) ________ is a variable, usually a bool, that signals when a condition exists.
Flag
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.
If/else if
If s1 and s2 are string objects, s1 == s2 is true when
None of these because in each case one or more characters in the strings have different ASCII codes.
The expression x < y is called a(n) ________ expression.
Relational
True/False: A pair of characters or a pair of string objects can be compared with any of the relational operators.
True
True/False: All of the relational operators are binary.
True
True/False: Assuming goodData is a Boolean variable, the following two tests are logically equivalent.if (goodData == false)if (!goodData)
True
True/False: If the sub-expression on the left side of an || operator is true, the expression on the right side will not be checked.
True
True/False: Relational expressions and logical expressions are both Boolean, which means they evaluate to true or false.
True
True/False: 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.
True
True/False: The statement pass = (score >= 7) ? true : false;does exactly the same thing as the if/else statement below:if (score >= 7)pass = true;elsepass = false;
True
What will the following statement do if x equals 17 and answer = 20? answer = x > 100 ? 0 : 1;
assign 1 to answer
A flag is a variable, usually of data type ________, that signals whether or not some condition exists.
bool
Relational operators allow you to ________ numbers.
compare
Which of the following correctly declares an enumerated data type named student?
enum student { Bill, Tom, Mary };
True/False: 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.
false
True/False: The following statements will not print anything.x = 5;if (x < 5) cout << "Hello "; cout << "world \n";
false
True/False: The scope of a variable is the program it is defined in.
false
The ________ statement causes other program statements to execute only under certain conditions.
if
The ________ statement executes one statement, or block of statements, if a condition is true and skips it, doing nothing, if the condition is false.
if
The ________ statement executes one block of statements if a test condition is true, and another block if the condition is false.
if/else
When a program lets the user know that an invalid menu choice has been made, this is an example of
input validation.
When an if statement is placed within the conditionally-executed code of another if statement, this is known as a(n)
nested if
A trailing else placed at the end of an if/elseif statement provides a default action when ________ of the if conditions is/are true.
none
The default section of a switch statement performs a similar task as the ________ portion of an if/elseif statement.
trailing else
True/False: An expression in a C++ if statement that evaluates to 5, -5, or for that matter anything other than 0, is considered true.
true
True/False: Assuming moreData is a Boolean variable, the following two tests are logically equivalent.if (moreData == true)if (moreData)
true
What will the following expression evaluate to?!( 6 > 7 || 3 == 4)
true
The ________ operator is known as the logical OR operator.
||