CH5 Quiz

24 July 2022
4.7 (114 reviews)
15 test answers

Unlock all answers in this set

Unlock answers (11)
question
A loop that continues to execute endlessly is called a(n) ____ loop.
answer
infinite
question
A(n) ____-controlled while loop uses a bool variable to control the loop.
answer
flag
question
Consider the following code. (Assume that all variables are properly declared.) cin >> ch; while (cin) { cout << ch; cin >> ch; } This code is an example of a(n) ____ while loop.
answer
EOF-controlled
question
In ____ structures, the computer repeats particular statements a certain number of times depending on some condition(s).
answer
looping
question
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; } cout << sum << endl;
answer
125
question
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; cin >> num; } cout << sum << endl;
answer
110
question
The ____ statement can be used to eliminate the use of certain (flag) variables.
answer
break
question
What executes immediately after a continue statement in a while and do-while loop?
answer
loop-continue test
question
What is the output of the following C++ code? count = 1; num = 25; while (count < 25) { num = num - 1; count++; } cout << count << " " << num << endl;
answer
25 1
question
What is the output of the following C++ code? num = 10; while (num > 10) num = num - 2; cout << num << endl;
answer
10
question
What is the output of the following loop? count = 5; cout << 'St'; do { cout << 'o'; count--; } while (count <= 5);
answer
This is an infinite loop.
question
Which executes first in a do...while loop?
answer
the statement
question
Which of the following is a repetition structure in C++?
answer
do...while
question
Which of the following statements generates a random number between 0 and 50? a. srand(time(0)); num = rand() % 50; c. srand(time(0)); num = rand()50; b. srand(time(10)); num = rand()/50; d. srand(time(10)); num = rand() % 50;
answer
srand(time(0)); num = rand() % 50;
question
____ loops are called posttest loops.
answer
do...while