Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

6. (TCO 3) What is the output of the following code snippet? int a = 9, b = 4, c

ID: 3629083 • Letter: 6

Question

6.
(TCO 3) What is the output of the following code snippet?


int a = 9, b = 4, c = -1;
if (a > b || (c = a) > 0)
{
cout << "TRUE" << a << b << c;
} else {
cout << "FALSE" << a << b << c;
}

(Points : 5)
FALSE 9 4 9
TRUE 9 4 -1
TRUE 9 4 -1
None of the above

7.
(TCO 3) What is the value of beta after the following code executes if the input is 5?



int beta;
cin >> beta;
switch(beta)
{
case 3:
beta += 3;
case 1:
beta++;
break;
case 5:
beta += 5;
case 4:
beta += 4;
}
(Points : 5)
14
9
10
5

8. (TCO 4) Which looping construct would be best suited when a program must repeat a set of tasks until a specific condition occurs? It is possible that the set of tasks will not need to execute at all if the specific conditions exists initially. (Points : 5)
for
do while
while
Any of the above

9.
(TCO 4) How many times does the following loop body execute?

int count = 52;
for(int i = 0; i < 26; i++)
{
cout << count << endl;
--count;
}
(Points : 5)
26
52
25
None of the above

10. (TCO 4) When the ________ statement is executed in a loop body, the remaining statements in the loop body are skipped and control proceeds with the next iteration of the loop. (Points : 5)
continue
break
eof
conditional

11.
(TCO 4) Why is this code snippet an infinite loop?

char answer = 'y';
while (answer == 'y' || answer = 'Y')
{
cout << "Still in loop" << endl;
cout << "Continue? (y for yes, n for no)" << endl;
cin >> answer;
}
(Points : 5)
The first line sets the value of answer to 'y' and, once the loop is entered, can never be changed
It is a sentinel-controlled loop, but the user is never asked to enter data.
The test expression always evaluates to TRUE because the value of the right-hand expression is the ASCII code for Y, which is non-zero, and anything other than zero is TRUE.
None of the above: it is not an infinite loop; it repeats until the user enters anything other than the letter y (either upper or lower case).

Explanation / Answer

a) TRUE 9 4 -1 b) beta = 14 c) while d) 26 e) continue f) None of the above: it is not an infinite loop; it repeats until the user enters anything other than the letter y (either upper or lower case).

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote