Question 1. What are the values of the variables after the code fragment below e
ID: 3553362 • Letter: Q
Question
Question 1. 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;
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
Question 2. For readability, all statements inside an if statement body should be
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.
Question 3. Which of the following statements about comments is false?
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.
Question 4.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 _______.
a SWITCH statement
multiple IF statements
nested IF statements
multiple IF ELSE statements
Question 5. 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.
if(100 < var && var < 0)
if(100 < var || var < 0)
if(0 <= var <= 100)
if(0 <= var && var <= 100)
Question 6. Which of the following values of the variable code will produce the same output for the two code fragments?
if(code < 1)
if(code < 1)
cout << "First"; cout << "First";
if(code < 2) else if(code < 2)
cout << "Second"; cout << "Second";
if(code < 3) else
cout << "Third"; cout << "Third";
0
1
2
None of the above
Question 7. 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;
}
14
9
10
5
Question 8. 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.
for
do while
while
Any of the above
Question 9. How many times does the following loop body execute?
int count = 52;
for(int i = 26; i >= 0; i--)
{
cout << count << endl;
--count;
}
26
52
27
None of the above
Question 10. When the _______ statement executes in a loop body, control immediately exits from the loop.
break
continue
exit
done
Question 11.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?
while(answer == 'y' && answer == 'Y')
while(answer == "y" && answer == "Y")
while(answer == 'y' || answer == 'Y')
while(answer == "y" || answer == "Y")
Question 1. 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;
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
Explanation / Answer
Q1.
x = 37.0, y = 32, z = 86
Q2.
surrounded by an open and closing parenthesis.
Q3.
A programmer should not claim ownership of a program by placing his or her name in a comment at the start of the program.
Q4.
nested IF statements
Q5.
if(0 <= var && var <= 100)
Q6.
2
Q7.
10
Q8.
while
Q9.
27
Q10.
break
Q11.
while(answer == 'y' && answer == 'Y')
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.