Quiz 5 Flashcards

1
Q

The following while loop terminates when j > 20.

j = 0;
while (j < 20)
j++;

A) True
B) False
A

False

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

The number of iterations of a counter-controlled loop is known in advance.

A) True
B) False
A

True

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

The control statements in the for loop include the initial statement, loop condition, and update statement.

A) True
B) False
A

True

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

The control variable in a flag-controlled while loop is a bool variable.

A) True
B) False
A

True

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

What is the output of the following C++ code?

count = 1;
num = 25;
while (count < 25)
{
num = num - 1;
count++;
}
cout &laquo_space;count &laquo_space;” “ &laquo_space;num &laquo_space;endl;

A) 24 0

B) 24 1

C) 25 0

D) 25 1

A

25 1

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

Consider the following code. (Assume that all variables are properly declared.)

cin&raquo_space; ch;

while (cin)
{
cout &laquo_space;ch;
cin&raquo_space; ch;
}

This code is an example of a(n) ____ while loop.

A) sentinel-controlled

B) flag-controlled

C) EOF-controlled

D) counter-controlled

A

C) EOF-controlled

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

Suppose sum, num, and j are int variables, and the input is 4 7 12 9 -1. What is the output of the following code?

cin&raquo_space; sum;
cin&raquo_space; num;
for (j = 1; j <= 3; j++)
{
cin&raquo_space; num;
sum = sum + num;
}
cout &laquo_space;sum &laquo_space;endl;

A) 24

B) 25

C) 41

D) 42

A

24

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

____ loops are called posttest loops.

A) break

B) for

C) while

D) do…while

A

D) do…while

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

Consider the following code.

int limit;
int reps = 0;

cin&raquo_space; limit;

while (reps < limit)
{
cin&raquo_space; entry;
triple = entry * 3;
cout &laquo_space;triple;
reps++;

}
cout &laquo_space;endl;

This code is an example of a(n) ____ while loop.

A) flag-controlled

B) counter-controlled

C) EOF-controlled

D) sentinel-controlled

A

B) counter-controlled

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

In ____ structures, the computer repeats particular statements a certain number of times depending on some condition(s).

A) looping

B) branching

C) selection

D) sequence

A

looping

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

Suppose j, sum, and num are int variables, and the input is 26 34 61 4 -1. What is the output of the code?

sum = 0;
cin&raquo_space; num;
for (int j = 1; j <= 4; j++)
{
sum = sum + num;
cin&raquo_space; num;
}
cout &laquo_space;sum &laquo_space;endl;

A) 124

B) 125

C) 126

D) 127

A

125

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

Assume that all variables are properly declared. The following for loop executes 20 times.

for (i = 0; i <= 20; i++)
cout &laquo_space;i;
A) True
B) False

A

False

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

Assume all variables are properly declared. The output of the following C++ code is 2 3 4 5.

n = 1;
while (n < 5)
{
n++;
cout &laquo_space;n &laquo_space;” “;
}

A) True
B) False
A

True

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

What is the output of the following C++ code?

num = 10;
while (num > 10)
num = num - 2;
cout &laquo_space;num &laquo_space;endl;

A)
0

B) 6

C) 8

D) 10

A

10

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

Suppose sum and num are int variables, and the input is 18 25 61 6 -1. What is the output of the following code?

sum = 0;
cin&raquo_space; num;
while (num != -1)
{
sum = sum + num;
cin&raquo_space; num;
}
cout &laquo_space;sum &laquo_space;endl;

A) 92

B) 109

C) 110

D) 119

A

110

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

Which of the following statements generates a random number between 0 and 50?

A) srand(time(0));
num = rand() % 50;

B) srand(time(10));
num = rand()/50;

C) srand(time(0));
num = rand()50;

D) srand(time(10));
num = rand() % 50;

A

A) srand(time(0));
num = rand() % 50;

17
Q

A loop that continues to execute endlessly is called a(n) ____ loop.

A) end

B) unhinged

C) infinite

D) definite

18
Q

Which of the following is a repetition structure in C++?

A) if

B) switch

C) while…do

D) do…while

A

D) do…while