Engineering Problem Solving with C++, 3e Chapter 4 Test Bank
6. Show the output of the following program using the input data: 8 -3 20
#include<iostream>
using namespace std;
int main()
{ int N, R, S;
cout << “Enter a list of integers terminated by 20.”;
S=1;
R=0;
do
{
cin >> N;
R++;
S = S + N;
} while (N < 20);
cout << “S = ” << S << “ R = “ << R;
return 0;
}
7. Write a short C++ program to read positive integers, until the value -1 is read and print the
sum of the values.
8. Which control statement is best used when you know how many times to repeat the
execution of a group of statements?
A. the do-while statement
B. the for statement
C. the switch statement
D. the while statement
9. The control statement which is best used when you need to select from among many integer
choices is the . . .
A. for statement
B. while statement
C. do/while statement
D. switch statement
10. The control statement which is best used when you want to repeat a group of statements
based on a condition and the statements in the loop body must be executed at least once is the
. . .
A. the for statement
B. the while statement
C. the do/while statement
D. the switch statement
11. When more than one statement appears in a loop body . . .
A. the loop body must be enclosed in parentheses, ( )
B. the loop body must be enclosed in curly braces, { }
C. the compiler requires that the statements in the loop body be indented.
D. there is nothing required to specify that there is more than one statement to the compiler