Charan
Charan
Charan
A. -9
B. 32
C. 45.5
D. 7
2. Which of the following for clauses processes the loop instructions as long as the x
variable's values is less than or equal to the number 100?
A. for(x=10; x <= 100; x=x+10)
B. for(x=10, x <= 100, x=x+10)
C. for(x==10; x <= 100; x=x+10)
D. for(x=x+10; x <= 100; x=10)
3. The computer will stop processing the loop associated with the for clause for(x=10; x <=
100; x=x+10) the x variable contains the number _____.
A. 100
B. 111
C. 101
D. 110
4.Which of the following while clauses tells the computer to exit the loop when the value in
the age variable is less than the number 0?
A. while (age<0)
B. while age>=0;
C. while (age != 0)
D. while (age>=0)
5.Which of the following is a good sentinel value for a program that allows the user to enter
a person's age?
A. -4 (Because a age can never be negative. Age 350 and 999 is possible we are
considering some historical person)
B. 350
C. 999
D. all of the options
6.A program allows the user to enter one or more numbers. The first input instructions will
get the first number only and is referred to as the _____ read.
A. entering
B. initializer
C. initializing
D. priming
7.How many times will the computer process the cout<<numTimes<<endl; statement in the
following code?
int numTimes = 0;
while(numTimes > 3)
{
cout << numTimes << endl;
numTimes = numTimes + 1;
}
A. 0
B. 1
C. 3
D. 4
8.How many times will the computer process the cout<<numTimes<<endl; statement in the
following code?
for(numTimes=1; numTimes<6; numTimes=numTimes + 1 )
cout << numTimes << endl;
A. 0
B. 1
C. 5
D. 6
9.What value in the numTimes variable stops the loop in the following statement?
for(numTimes=1; numTimes<6; numTimes=numTimes + 1 )
cout << numTimes << endl;
A. 1
B. 5
C. 6
D. 7
10.How many times will the computer process the cout<<numTimes<<endl; statement in
the following code?
for(numTimes= 4; numTimes<=10 ; numTime=numTimes+2)
cout <<numTimes <<endl;
A. 0
B. 3
C. 4
D. 12
11.What value in the numTimes variable stops the loop in the following statement?
for(numTimes= 4; numTimes<=10 ; numTime=numTimes+2)
cout <<numTimes <<endl;
A. 4
B. 6
C. 10
D. 12
12.Which of the following updates the total accumulator variable by the value in the sales
variable?
A. total = total + sales;
B. total = sales + total;
C. total += sales;
D. all of the option
13.Which of the following statements can be used to code a loop whose instructions you
want to processed 10 times?
A. for
B. repeat
C. while
D. either for or while
14. The while clause in the C++ do while statement ends with a ______.
A. brace
B. colon
C. comma
D. semicolon
15. Which of the followig can be used to code the mathematical expression 10^2?
A. pow(10.2 , 2.0)
B. pow(10.2 , 2)
C. pow(10 , 2.0)
D. all choices
16.The instructions in the body of the ____statements are always processed at least once
during runtime.
A. do while
B. for
C. while
D. both do while and for
17.It's possible that the instructions in the body of the ____ statement will not be processed
during runtime.
A. do while
B. for
C. while
D. both for and while
18.What numbers will the following code display on the computer screen?
int x = 1;
do
{
cout << x << endl;
x = x + 1;
}while (x<5);
A. 0, 1, 2, 3, 4
B. 0, 1, 2, 3, 4, 5
C. 1, 2, 3, 4
D. 1, 2, 3, 4, 5
19.What numbers will the following code display on the computer screen?
int x = 20;
do
{
cout << x << endl;
x = x - 4;
} while ( x>10);
A. 16, 12, 8
B. 16, 12
C. 20, 16, 12, 8
D. 20, 16, 12
25.Which of the following declares a one-dimensional int array named quantities and
initializes each of its 20 elements to the number 0?
A. int quantities[20] = {0};
B. int quantities(20) = {0};
C. int quantities{20} = 0;
D. none of the choices
26.Which of the following calls the value-returning getTotal function, passing it the quantities
array and the number of array elements?
A. total = getTotal(quantities[], 20);
B. total = getTotal(quantities[20]);
C. total = getTotal(quantities, 20);
D. none of the choices
27.Which of the following adds the contents of the third element in the orders array to the
total variable? Both the vairable and the array have the int data type.
A. orders[2] += total;
B. orders[3] += total;
C. total += orders[2];
D. total += orders[3];
28.Which of the following if clauses determines whether the value stored in the fourth
element in the orders array is greater than 25? The array has the int data type.
A. if(orders(3) > 25)
B. if(orders{4} > 25)
C. if(orders[3] > 25)
D. if(orders[4] > 25
29.Which of the following if clauses determines whether an int variable named sub contain a
valid subscript for the scores array? The array has 10 elements.
A. if(sub>0 && sub<10)
B. if(sub>=0 && sub<=10
C. if(sub>=0 && sub<10)
D. if(sub>0 && sub <=10)
30.Which of the following while clauses tells the computer to process the loop instructions
for each of the elements in the inventory array? The program uses an int variable named x
to keep track of the array subscripts. The x variable is initialized to 0.
A. while (x<20)
B. while (x <= 20)
C. while (x>0)
D. while (x>=0)
Answer 30: This question has one information missing which is the size of the inventory
array. If the size of the array is 20 then the correct answer is option A. while (x<20) but if
the array size is 21 then the correct answer is option B. while (x <= 20)