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

1. What are the values of the variables after the code fragment below executes i

ID: 3533867 • Letter: 1

Question

1. 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 >> y;
cin >> z;



      x = 37, y = 86.56, z = 32
      
x = 37, y = 86, z = 32
      
x = 37, y = 86, z = 0.56
      
x = 37, y = 86, z = 32.56

2. For readability, all statements inside a loop body should be (Points : 5)

      indented the same distance as the loop control statement.
      
indented by one additional tab stop more than the loop control statement.
      
surrounded by an open and closing parenthesis.
      
written on the same line.

3. Which of the following lines correctly adds a multiline comment? (Points : 5)

      // comment
    comment \

      
/* comment
   * comment
   */

      
/* comment
  */ comment

      
\ comment
  \ comment


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 _______. (Points : 5)

      a SWITCH statement
      
multiple IF statements
      
nested IF statements
      
multiple IF ELSE statements

5. Which statement correctly tests char variable keepgoing for the upper or lower case letter A? (Points : 5)

      if(keepgoing = 'a' || keepgoing = 'A')
      
if(keepgoing = 'a' || 'A')
      
if(keepgoing == 'a' && keepgoing == 'A')
      
if(keepgoing == 'a' || keepgoing == 'A')

6.
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.
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. Which looping construct guarantees that the loop body always executes at least one time? (Points : 5)

      for
      
do while
      
while
      
any of the above

9.
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. 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.
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).

1. 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 >> y;
cin >> z;



      x = 37, y = 86.56, z = 32
      
x = 37, y = 86, z = 32
      
x = 37, y = 86, z = 0.56
      
x = 37, y = 86, z = 32.56

Explanation / Answer

1.x = 37, y = 86, z = 32

2.
surrounded by an open and closing parenthesis.

3.
/* comment
  */ comment

4.
SWITCH statement

5.if(keepgoing = 'a' || keepgoing = 'A')

6.TRUE 9 4 -1

7.a)14

8.b)do while

9.c)27

10.b) break

11The 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.