1. (TCO 2) What are the values of the variables after the code fragment below ex
ID: 3627647 • 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?
double x, y;
int z;
cin >> x;
cin >> z;
cin >> y;
(Points : 5)
x = 37.0, y = 32, z = 86
x = 37.0, y = 56, z = 86
x = 37.0, y = 32, z = 86.56
x = 37.0, y = 0.56, z = 86
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 statements about comments is false? (Points : 5)
All comments are ignored by the compiler.
A comment block at the start of a program file should contain information about what the program does.
Comments are used to explain the program code to anyone who reads the program code.
A programmer should not claim ownership of a program by placing his or her name in a comment at the start of the program.
4. (TCO 3) Based on input of a single digit code, your program must output the full name of a US state plus other information about the state based on its population category. 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 || (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) 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 = 0; i < 26; i++)
{
cout << count << endl;
--count;
} (Points : 5)
26
52
25
None of the above
10. (TCO 4) When the _______ statement executes in a loop body, control immediately exits from the loop. (Points : 5)
break
continue
exit
done
11. (TCO 4) Which of the following expressions is correct if you want to end a while-loop when the character variable answer is anything other than the character 'y' in either upper or lower case? (Points : 5)
while(answer == 'y' && answer == 'Y')
while(answer == "y" && answer == "Y")
while(answer == 'y' || answer == 'Y')
while(answer == "y" || answer == "Y")
Explanation / Answer
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?
double x, y;
int z;
cin >> x;
cin >> z;
cin >> y;
(Points : 5)
x = 37.0, y = 32, z = 86
x = 37.0, y = 56, z = 86
x = 37.0, y = 32, z = 86.56
x = 37.0, y = 0.56, z = 86
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.
3. (TCO 10) Which of the following statements about comments is false? (Points : 5)
All comments are ignored by the compiler.
A comment block at the start of a program file should contain information about what the program does.
Comments are used to explain the program code to anyone who reads the program code.
A programmer should not claim ownership of a program by placing his or her name in a comment at the start of the program.
4. (TCO 3) Based on input of a single digit code, your program must output the full name of a US state plus other information about the state based on its population category. The best selection structure to use to program this situation is _______. (Points : 5)
a SWITCH statement
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)
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
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
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 = 0; i < 26; i++)
{
cout << count << endl;
--count;
} (Points : 5)
26
10. (TCO 4) When the _______ statement executes in a loop body, control immediately exits from the loop. (Points : 5)
break
11. (TCO 4) Which of the following expressions is correct if you want to end a while-loop when the character variable answer is anything other than the character 'y' in either upper or lower case? (Points : 5)
while(!(answer == "y" || answer == "Y"))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.