Quiz 4 Flashcards

1
Q

A switch statement can contain any number of case labels in any order.

A) True
B) False
A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

In C++, strings of characters cannot be compared.

A) True
B) False
A

false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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

A

break

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In C++, Boolean variables are declared with the ____ keyword.

A) bool

B) true

C) boolean

D) false

A

bool

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

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

A

integer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Logical operators AND, OR, and NOT are represented by the symbols &&, ____, and !, respectively.

A) |

B) «

C)&raquo_space;

D) ||

A

||

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Using the abs() function requires including the ____ header file.

A) cnumber

B) math

C) cmath

D) iostream

A

cmath

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A(n) ____ is any combination of operands and operators that yields a result.

A) statement

B) expression

C) sentence

D) command

A

expression

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A

if-else

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

***In C++, the postfix and prefix – operators can be applied to Boolean variables.

A) True
B) False
A

false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

In a ____ control structure, the computer executes particular statements depending on some condition(s).

A) looping

B) repetition

C) selection

D) sequence

A

selection

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which of the following is the “not equal to” relational operator?
Question options:

A) !

B) |

C) !=

D) &

A

!=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

A control structure alters the normal sequential flow of execution in a program.

A) True
B) False
A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The operators !, &&, and || are called relational operators.

A

false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which of the following is a relational operator?

A) =

B) ==

C) !

D) &&

A

==

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

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

17
Q

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 &laquo_space;x &laquo_space;” “ &laquo_space;y &laquo_space;” “ &laquo_space;z &laquo_space;endl;

A) 35 45 80

B) 35 45 10

C) 35 45 –10

D) 35 45 0

18
Q

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 &laquo_space;y &laquo_space;endl;

A) 2

B) 5

C) 8

D) 10

19
Q

The condition used in an if statement can be any valid C++ expression.
A) True
B) False

20
Q

The relational operator ____ is used to represent the condition “less than.”

A) <

B) >

C) «

D) <=

21
Q

Including one or more if statements inside an existing if statement is called a ____ if statement.

A) composed

B) compound

C) complex

D) nested

22
Q

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

23
Q

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

A) (x > 0) || ( x <= 0)

24
Q

In C++, the logical ____ operator is used to change an expression to its opposite state.

A) OR

B) AND

C) NOT

D) REVERSE

25
Q

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

26
Q

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