Ch.3 Flashcards

1
Q

Which boolean operation is described by the following table?

A B Operation
True True True
True False True
False True True
False False False

A

or

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

Which of the following data types may be used in a switch statement?

A) long

B) char

C) enum

D) int

E) all of the above

A

all of the above

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

What is the value of the following expression?

(true && (4/3 || !(6)))

A

true

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

When testing a program with a loop, which of the following tests should be done?

A) one less than the maximum number of iterations

B) no iterations of the loops

C) the maximum number of iterations

D) one more than the maximum number of iterations

E) A, B, and C

A

one less than the maximum number of iterations

no iterations of the loops

the maximum number of iterations

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

Which of the following is not a good reason for choosing a certain loop control?

A) What the loop does

B) If the loop is in a function

C) The condition for ending the loop

D) The minimum number of iterations of the loop

A

If the loop is in a function

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

Which of the following data types can be used in a switch controlling expression?

A) char

B) enum

C) float

D) int

E) A, B, and D

A

char

enum

int

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

Which boolean operation is described by the following table?

A B Operation
True True True
True False False
False True False
False False False

A

and

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

Given the following enumerated data type definition, what is the value of SAT?

enum myType{SUN=3,MON=1,TUE=3,WED,THUR,FRI,SAT,NumDays};

A

7

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

What is the output of the following code fragment?

int i = 5;

switch(i)

{

case 0:i = 15;break;

case 1:i = 25;break;

case 2:i = 35;break;

case 3:i = 40;

default:i = 0;

}

A

0

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

If you want a loop to quit iterating if x < 10 and y > 3, what would be the proper loop condition test?

A

(x >= 10 || y <= 3)

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

Given the following enumerated data type definition, what is the value of SAT?

enum myType{SUN,MON,TUE,WED,THUR,FRI,SAT,NumDays};

A

6

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

What is the value of x after the following code executes?

int x = 10;

if( ++ x > 10)

{

x = 13;

}

A

13

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

What is the value of x after the following code executes?

int x = 10;

if(x ++ > 10)

{

x = 13;

}

A

11

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

Which of the following are equivalent to (!(x < 15 && y >= 3))?

A

(x >= 15 || y < 3)

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

If you need to write a do-while loop that will ask the user to enter a number between 2 and 5 inclusive, and will keep asking until the user enters a correct number, what is the loop condition?

A

(2 > number || number > 5)

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

If a programming language does not use short-circuit evaluation, what is the output of the following code fragment if the value of myInt is 0?

int other = 3, myInt;

if(myInt != 0 && other % myInt != 0)

cout ≤≤ “other is odd\n”;

else

cout << “other is even\n”;

A

run-time error, no output

17
Q

What is wrong with the following for loop?

for(int i = 0;i < 10;i – )

{

cout << “Hello\n”;

}

A

infinite loop

18
Q

Which of the following are allowed in the third section of the for loop statement?

A) i ++

B) cout << “Hello\n”

C) i –

D) i += 2

E) all of the above

A

all of the above

19
Q

What is the output of the following code fragment?

int x = 0;

{

int x = 13;

cout ≤≤ x ≤≤ “,”;

}

cout ≤≤ x ≤≤ endl;

A

13,0

20
Q

Which of the following symbols has the highest precedence?

A

++

21
Q

A ________ expression is an expression that can be thought of as being true or false.

A

boolean

22
Q

A loop that iterates one too many or one too few times is said to be

A

off-by-one

23
Q

is a type whose values are defined by a list of constants of type int

A

enum

24
Q

Variables defined inside a set of braces are said to be ________ to that block of code

A

local

25
Q

A switch statement variable must be

A

an int char enum

26
Q

Each repetition of a loop body is called

A

iteration

27
Q

The compiler always pairs an else with

A

e nearest unpaired if

28
Q

In a compound logical and (&&) expression, the evaluation of the expression stops once one of the terms of the expression is false. This is known as ________ evaluation

A

short circuit

29
Q

A semicolon by itself is a valid C++ statement

A

True

30
Q

A break statement in a switch stops your program

A

False

31
Q

The break statement causes all loops to exit

A

False

32
Q

All switch statements can be converted into nested if-else statements

A

True

33
Q

A function may return a boolean value

A

True