1. (TCO 2) What are the values of the variables after the code fragment below ex
ID: 3627656 • Letter: 1
Question
1. (TCO 2) What are the values of the variables after the code fragment below executes if the input data is 37 86.56 32?int x, y;
double z;
cin >> x;
cin >> z;
cin >> y;
(Points : 5)
x = 37, y = 86.56, z = 32
x = 37, y = 32, z = 86.56
x = 37, y = 86, z = 32
x = 37, y = 86, z = 56
2. (TCO 10) For readability, all statements inside an if statement body should be (Points : 5)
indented the same distance as the if statement.
surrounded by an open and closing parenthesis.
indented by one additional tab stop more than the if statement.
written on the same line.
3. (TCO 10) Which of the following lines correctly adds a multiline comment? (Points : 5)
// comment
comment \
/* comment
* comment
*/
/* comment
*/ comment
\ comment
\ comment
4. (TCO 3) A program needs to calculate an employee's withholding for the week. Besides all the normal deductions that apply to everyone, a deduction for 401K savings must be withheld if the employee is enrolled in the 401K plan. Also, several other deductions may need to be withheld if an employee has elected to enroll in those benefits. The best selection structure to use to program this situation is _______. (Points : 5)
a SWITCH statement
multiple IF statements
nested IF statements
multiple IF ELSE statements
5. (TCO 3) Which statement correctly tests int variable var to be outside the range from 0 to 100? Note that 0 and 100 are considered to be within the range. (Points : 5)
if(100 < var && var < 0)
if(100 < var || var < 0)
if(0 <= var <= 100)
if(0 <= var && var <= 100)
6.
(TCO 3) What is the output of the following code snippet?
int a = 9, b = 4, c = -1;
if (a < b && (a = c) > 0)
{
cout << "TRUE" << a << b << c;
} else {
cout << "FALSE" << a << b << c;
} (Points : 5)
FALSE 9 4 -1
TRUE -1 4 -1
FALSE -1 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) Your program must repeat a set of tasks exactly 15 times. Which looping construct is best suited for this situation? (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 = 26; i >= 0; i--)
{
cout << count << endl;
--count;
} (Points : 5)
26
52
27
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
please rate - thanks
message me if you need any explanations
1. (TCO 2) What are the values of the variables after the code fragment below executes if the input data is 37 86.56 32?
int x, y;
double z;
cin >> x;
cin >> z;
cin >> y;
(Points : 5)
x = 37, y = 86.56, z = 32
x = 37, y = 32, z = 86.56
x = 37, y = 86, z = 32
x = 37, y = 86, z = 56
2. (TCO 10) For readability, all statements inside an if statement body should be (Points : 5)
indented the same distance as the if statement.
surrounded by an open and closing parenthesis.
indented by one additional tab stop more than the if statement.
written on the same line.
3. (TCO 10) Which of the following lines correctly adds a multiline comment? (Points : 5)
// comment
comment \
/* comment
* comment
*/
/* comment
*/ comment
\ comment
\ comment
4. (TCO 3) A program needs to calculate an employee's withholding for the week. Besides all the normal deductions that apply to everyone, a deduction for 401K savings must be withheld if the employee is enrolled in the 401K plan. Also, several other deductions may need to be withheld if an employee has elected to enroll in those benefits. The best selection structure to use to program this situation is _______. (Points : 5)
a SWITCH statement
multiple IF statements
nested IF statements
multiple IF ELSE statements
5. (TCO 3) Which statement correctly tests int variable var to be outside the range from 0 to 100? Note that 0 and 100 are considered to be within the range. (Points : 5)
if(100 < var && var < 0)
if(100 < var || var < 0)
if(0 <= var <= 100)
if(0 <= var && var <= 100)
6.
(TCO 3) What is the output of the following code snippet?
int a = 9, b = 4, c = -1;
if (a < b && (a = c) > 0) // a<b false so nothing else done
{
cout << "TRUE" << a << b << c;
} else {
cout << "FALSE" << a << b << c;
} (Points : 5)
FALSE 9 4 -1
TRUE -1 4 -1
FALSE -1 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) Your program must repeat a set of tasks exactly 15 times. Which looping construct is best suited for this situation? (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 = 26; i >= 0; i--)
{
cout << count << endl;
--count;
} (Points : 5)
26
52
27
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') //none of the above this will not compile
{
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).
assuming the code is
char answer = 'y';
while (answer == 'y' || answer =='Y')
{
cout << "Still in loop" << endl;
cout << "Continue? (y for yes, n for no)" << endl;
cin >> answer;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.