Please check my answers and explain the errors that I made True/False Indicate w
ID: 3558414 • Letter: P
Question
Please check my answers and explain the errors that I made
True/False
Indicate whether the sentence or statement is true or false.
FALSE____ 1. The following is not a valid for statement:
for(int x=1; x<6; ++x)
cout<<c;
Multiple Choice
Identify the letter of the choice that best completes the statement or answers the question.
B____ 2.
cout<<"Loop";
will not print the word Loop at all.
a.
for(k = 0; k < 6; k++)
b.
for(a = 3; a < 2; a++)
c.
for(c = 4; c >= 3; c++)
d.
All will print the word Loop at least once.
B____ 3. In the following lines of code
int counter = 1;
while (counter <= 3)
{
counter = counter + 1;
}
the loop condition will be evaluated ____ times.
a. 0
b. 2
c. 3
d. 4
Completion
Complete each sentence or statement.
?? 4. How many numbers are printed out by the following lines of code?
for(value = 2; value < 6; ++value)
cout<<value;
____________________
Short Answer
5. Add the statements necessary to create a do...while statement that prints the value of ctCount ? when it is less than 10.
int ctCount = 1;
do
cout<< ctCount<<;
}while(ctCount<10);
6. Write a for statement to print the numbers 3,2,1 on separate lines. Use ctCount as your variable.
for(ctCount=4;ctCount<=1;--ctCount)
A____7. What is the output of the following code segment?
n = 1;
for ( ; n <= 5; )
cout << n << ' ';
n++;
a. 1 2 3 4 5 d. 1 2 3 4
b. 1 1 1 forever e. 2 3 4 5
c. 2 3 4 5 6
C___8. A(n) _________loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop.
a. do-while
b. while
c. for
d. infinite
e. None of these
TRUE__9. True/False: The update expression of a for loop can contain more than one statement, e.g. counter++, total+= sales.
B_10. The ________ statement causes a loop to terminate early.
a. stop
b. break
c. null
d. terminate
e. None of these
B__11. If you want a user to enter exactly 20 values, which loop would you use?
a. do-while
b. for
c. while
d. infinite
e. None of these
Explanation / Answer
Indicate whether the sentence or statement is true or false.
FALSE____ 1. The following is not a valid for statement:
for(int x=1; x<6; ++x)
cout<<c;
Identify the letter of the choice that best completes the statement or answers the question.
B____ 2.
cout<<"Loop";
will not print the word Loop at all.
b.
for(a = 3; a < 2; a++)
C____ 3. In the following lines of code
int counter = 1;
while (counter <= 3)
{
counter = counter + 1;
}
the loop condition will be evaluated ____ times.
c. 3 //Loop Condition will be executed 3 TIMES.
Complete each sentence or statement.
?? 4. How many numbers are printed out by the following lines of code?
for(value = 2; value < 6; ++value)
cout<<value;
4 numbers will be printed. (2,3,4,5)
Add the statements necessary to create a do...while statement that prints the value of ctCount ? when it is less than 10.
int ctCount = 1;
do
{
cout<< ctCount;
ctCount++;
}while(ctCount<10);
6. Write a for statement to print the numbers 3,2,1 on separate lines. Use ctCount as your variable.
for(ctCount=3;ctCount>=1;--ctCount) // You should start with 3 not with 4.
B____7. What is the output of the following code segment?
n = 1;
for ( ; n <= 5; )
cout << n << ' ';
n++;
b. 1 1 1 forever it prints 1 1 1 forever...because n is incrementd outside for loop..
C___8. A(n) _________loop is a good choice when you know how many times you want the loop to iterate in advance of entering the loop.
c. for
TRUE__9. True/False: The update expression of a for loop can contain more than one statement, e.g. counter++, total+= sales.
B_10. The ________ statement causes a loop to terminate early.
b. break
B__11. If you want a user to enter exactly 20 values, which loop would you use?
b. for