Quiz 4 Flashcards
A switch statement can contain any number of case labels in any order.
A) True B) False
True
In C++, strings of characters cannot be compared.
A) True B) False
false
The ____ statement identifies the end of a particular case and causes an immediate exit from the switch statement.
A) default
B) exit
C) stop
D) break
break
In C++, Boolean variables are declared with the ____ keyword.
A) bool
B) true
C) boolean
D) false
bool
The expression in the switch statement must evaluate to a(n) ____ result or a compilation error results.
A) boolean
B) integer
C) long
D) character
integer
Logical operators AND, OR, and NOT are represented by the symbols &&, ____, and !, respectively.
A) |
B) «
C)»_space;
D) ||
||
Using the abs() function requires including the ____ header file.
A) cnumber
B) math
C) cmath
D) iostream
cmath
A(n) ____ is any combination of operands and operators that yields a result.
A) statement
B) expression
C) sentence
D) command
expression
The ____ statement in C++ is used to implement a decision structure in its simplest form—choosing between two alternatives.
A) while
B) for
C) if-else
D) switch-case
if-else
***In C++, the postfix and prefix – operators can be applied to Boolean variables.
A) True B) False
false
In a ____ control structure, the computer executes particular statements depending on some condition(s).
A) looping
B) repetition
C) selection
D) sequence
selection
Which of the following is the “not equal to” relational operator?
Question options:
A) !
B) |
C) !=
D) &
!=
A control structure alters the normal sequential flow of execution in a program.
A) True B) False
true
The operators !, &&, and || are called relational operators.
false
Which of the following is a relational operator?
A) =
B) ==
C) !
D) &&
==
Suppose x is 5 and y is 7. Choose the value of the following expression:
(x != 7) && (x <= y)
A) false
B) true
C) 0
D) null
true
What is the output of the following C++ code?
int x = 35;
int y = 45;
int z;
if (x > y)
z = x + y;
else
z = y – x;
cout «_space;x «_space;” “ «_space;y «_space;” “ «_space;z «_space;endl;
A) 35 45 80
B) 35 45 10
C) 35 45 –10
D) 35 45 0
35 45 10
What is the output of the following C++ code?
int x = 55;
int y = 5;
switch (x % 7)
{
case 0:
case 1:
y++;
case 2:
case 3:
y = y + 2;
case 4:
break;
case 5:
case 6:
y = y – 3;
}
cout «_space;y «_space;endl;
A) 2
B) 5
C) 8
D) 10
2
The condition used in an if statement can be any valid C++ expression.
A) True
B) False
True
The relational operator ____ is used to represent the condition “less than.”
A) <
B) >
C) «
D) <=
<
Including one or more if statements inside an existing if statement is called a ____ if statement.
A) composed
B) compound
C) complex
D) nested
nested
Suppose P and Q are logical expressions. The logical expression P && Q is true if both P and Q are true.
A) True
B) False
true
Suppose that x is an int variable. Which of the following expressions always evaluates to true?
A) (x > 0) || ( x <= 0)
B) (x >= 0) || (x == 0)
C) (x > 0) && ( x <= 0)
D) (x > 0) && (x == 0)
A) (x > 0) || ( x <= 0)
In C++, the logical ____ operator is used to change an expression to its opposite state.
A) OR
B) AND
C) NOT
D) REVERSE
NOT
In the switch statement, the ____ keyword identifies values that are compared with the switch expression’s value.
A) label
B) default
C) break
D) case
case
In C++, when comparing character data, the char values are coerced to ____ values automatically for the comparison.
A) int
B) long
C) bool
D) unsigned int
int