978-1337102087 Chapter 5

subject Type Homework Help
subject Pages 9
subject Words 137
subject Authors D. S. Malik

Unlock document.

This document is partially blurred.
Unlock all pages and 1 million more documents.
Get Access
page-pf1
Name:
Class:
Date:
Copyright Cengage Learning. Powered by Cognero.
Page 1
1. The statement in the body of a while loop acts as a decision maker.
a.
True
b.
False
ANSWER:
False
POINTS:
1
REFERENCES:
269
QUESTION TYPE:
True / False
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
2. The following while loop terminates when j > 20.
j = 0;
while (j < 20)
j++;
a.
True
b.
False
ANSWER:
False
POINTS:
1
REFERENCES:
269
QUESTION TYPE:
True / False
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
3. The number of iterations of a counter-controlled loop is known in advance.
a.
True
b.
False
ANSWER:
True
POINTS:
1
REFERENCES:
303
QUESTION TYPE:
True / False
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
4. Assume all variables are properly declared. The output of the following C++ code is 2 3 4 5.
n = 1;
while (n < 5)
{
n++;
page-pf2
Name:
Class:
Date:
Copyright Cengage Learning. Powered by Cognero.
Page 2
cout << n << " ";
}
a.
True
b.
False
ANSWER:
True
POINTS:
1
REFERENCES:
271
QUESTION TYPE:
True / False
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
5. In a counter-controlled while loop, the loop control variable must be initialized before the loop.
a.
True
b.
False
ANSWER:
True
POINTS:
1
REFERENCES:
274
QUESTION TYPE:
True / False
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
6. In the case of the sentinel-controlled while loop, the first item is read before the while loop is entered.
a.
True
b.
False
ANSWER:
True
POINTS:
1
REFERENCES:
277
QUESTION TYPE:
True / False
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
7. In a sentinel-controlled while loop, the body of the loop continues to execute until the EOF symbol is read.
a.
True
b.
False
ANSWER:
False
POINTS:
1
REFERENCES:
277
QUESTION TYPE:
True / False
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
page-pf3
Name:
Class:
Date:
page-pf4
Name:
Class:
Date:
page-pf5
Name:
Class:
Date:
Copyright Cengage Learning. Powered by Cognero.
Page 5
a.
end
b.
unhinged
c.
infinite
d.
definite
ANSWER:
c
POINTS:
1
REFERENCES:
269
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
15. Consider the following code.
int limit;
int reps = 0;
cin >> limit;
while (reps < limit)
{
cin >> entry;
triple = entry * 3;
cout << triple;
reps++;
}
cout << endl;
This code is an example of a(n) ____ while loop.
a.
flag-controlled
b.
counter-controlled
c.
EOF-controlled
d.
sentinel-controlled
ANSWER:
b
POINTS:
1
REFERENCES:
274
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
16. 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 >> num;
while (num != -1)
{
sum = sum + num;
page-pf6
Name:
Class:
Date:
Copyright Cengage Learning. Powered by Cognero.
Page 6
cin >> num;
}
cout << sum << endl;
a.
92
b.
109
c.
110
d.
119
ANSWER:
c
POINTS:
1
REFERENCES:
270-272
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
17. A(n) ____-controlled while loop uses a bool variable to control the loop.
a.
counter
b.
sentinel
c.
flag
d.
EOF
ANSWER:
c
POINTS:
1
REFERENCES:
283
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
18. 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;
ANSWER:
a
POINTS:
1
REFERENCES:
284
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
19. Consider the following code. (Assume that all variables are properly declared.)
cin >> ch;
while (cin)
{
cout << ch;
page-pf7
Name:
Class:
Date:
Copyright Cengage Learning. Powered by Cognero.
Page 7
cin >> ch;
}
This code is an example of a(n) ____ while loop.
a.
sentinel-controlled
b.
flag-controlled
c.
EOF-controlled
d.
counter-controlled
ANSWER:
c
POINTS:
1
REFERENCES:
287
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
20. What is the next Fibonacci number in the following sequence?
1, 1, 2, 3, 5, 8, 13, 21, ...
a.
34
b.
43
c.
56
d.
273
ANSWER:
a
POINTS:
1
REFERENCES:
293
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
21. What is the initial statement in the following for loop? (Assume that all variables are properly declared.)
int i;
for (i = 1; i < 20; i++)
cout << "Hello World";
cout << "!" << endl;
a.
i = 1;
b.
i < 20;
c.
i++;
d.
cout << "Hello World";
ANSWER:
a
POINTS:
1
REFERENCES:
298
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
22. What is the output of the following C++ code?
page-pf8
Name:
Class:
Date:
Copyright Cengage Learning. Powered by Cognero.
Page 8
int j;
for (j = 10; j <= 10; j++)
cout << j << " ";
cout << j << endl;
a.
10
b.
10 10
c.
10 11
d.
11 11
ANSWER:
c
POINTS:
1
REFERENCES:
299
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
23. 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 >> sum;
cin >> num;
for (j = 1; j <= 3; j++)
{
cin >> num;
sum = sum + num;
}
cout << sum << endl;
a.
24
b.
25
c.
41
d.
42
ANSWER:
a
POINTS:
1
REFERENCES:
298-299
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
24. 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 >> num;
for (int j = 1; j <= 4; j++)
{
sum = sum + num;
cin >> num;
page-pf9
Name:
Class:
Date:
Copyright Cengage Learning. Powered by Cognero.
Page 9
}
cout << sum << endl;
a.
124
b.
125
c.
126
d.
127
ANSWER:
b
POINTS:
1
REFERENCES:
298-299
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
25. Which of the following is a repetition structure in C++?
a.
if
b.
switch
c.
while...do
d.
do...while
ANSWER:
d
POINTS:
1
REFERENCES:
309
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
26. Which executes first in a do...while loop?
a.
the statement
b.
loop condition
c.
the expression
d.
update statement
ANSWER:
a
POINTS:
1
REFERENCES:
309
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
27. What is the value of x after the following statements execute?
int x = 5;
int y = 30;
do
x = x * 2;
while (x < y);
a.
5
b.
10
page-pfa
Name:
Class:
Date:
Copyright Cengage Learning. Powered by Cognero.
Page 10
c.
20
d.
40
ANSWER:
d
POINTS:
1
REFERENCES:
309
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
28. What is the output of the following loop?
count = 5;
cout << 'St';
do
{
cout << 'o';
count--;
}
while (count <= 5);
a.
St
b.
Sto
c.
Stop
d.
This is an infinite loop.
ANSWER:
d
POINTS:
1
REFERENCES:
309
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
29. ____ loops are called posttest loops.
a.
break
b.
for
c.
while
d.
do...while
ANSWER:
d
POINTS:
1
REFERENCES:
310
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
30. Which of the following loops does not have an entry condition?
a.
EOF-controlled while loop
b.
sentinel-controlled while loop
c.
do...while loop
d.
for loop
page-pfb
Name:
Class:
Date:
Copyright Cengage Learning. Powered by Cognero.
Page 11
ANSWER:
c
POINTS:
1
REFERENCES:
310
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
31. Which of the following loops is guaranteed to execute at least once?
a.
counter-controlled while loop
b.
for loop
c.
do...while loop
d.
sentinel-controlled while loop
ANSWER:
c
POINTS:
1
REFERENCES:
310
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
32. The ____ statement can be used to eliminate the use of certain (flag) variables.
a.
while
b.
switch
c.
break
d.
if
ANSWER:
c
POINTS:
1
REFERENCES:
313
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
33. What executes immediately after a continue statement in a while and do-while loop?
a.
loop-continue test
b.
update statement
c.
loop condition
d.
the body of the loop
ANSWER:
a
POINTS:
1
REFERENCES:
315
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
34. When a continue statement is executed in a ____, the update statement always executes.
a.
while loop
b.
for loop
page-pfc
Name:
Class:
Date:
Copyright Cengage Learning. Powered by Cognero.
Page 12
c.
switch structure
d.
do...while loop
ANSWER:
b
POINTS:
1
REFERENCES:
315
QUESTION TYPE:
Multiple Choice
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
35. To generate a random number, you can use the function rand of the header file ____________________.
ANSWER:
cstdlib
POINTS:
1
REFERENCES:
284
QUESTION TYPE:
Completion
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
36. The function eof is a member of the data type ____________________.
ANSWER:
istream
POINTS:
1
REFERENCES:
287
QUESTION TYPE:
Completion
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
37. A semicolon at the end of the for statement (just before the body of the loop) is a(n) ____________________ error.
ANSWER:
semantic
POINTS:
1
REFERENCES:
300
QUESTION TYPE:
Completion
HAS VARIABLES:
False
DATE CREATED:
10/5/2016 1:39 PM
DATE MODIFIED:
10/5/2016 1:39 PM
38. In a while and for loop, the loop condition is evaluated before executing the body of the loop. Therefore, while
and for loops are called ____________________ loops.
ANSWER:
pretest
POINTS:
1
REFERENCES:
310
QUESTION TYPE:
Completion
HAS VARIABLES:
False
page-pfd
Name:
Class:
Date:

Trusted by Thousands of
Students

Here are what students say about us.

Copyright ©2022 All rights reserved. | CoursePaper is not sponsored or endorsed by any college or university.