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

Part 1 1. Write equivalent compound statements if possible. a.x = 2 *x b.x = x +

ID: 667786 • Letter: P

Question

Part 1

1. Write equivalent compound statements if possible.

a.x = 2 *x

b.x = x + y - 2;

c.sum = sum + num;

d. z = z *x + 2 *z;

e. y = y / (x + 5);

2. Write the following compound statements as equivalent simple statements.

a.x += 5 - z;

b.y *= 2 *x + 5 - z;

c.w += 2 *z + 4;

d.x -= z + y - t;

e. sum += num;

3. Write C++ statement(s) that accomplish the following:

a.Declare int variables x and y. Initialize x to 25 and y to 18.

b.Declare and initialize an int variable temp to 10 and a char variable ch to 'A'.

c.Update the value of an int variable x by adding 5 to it.

d.Declare and initialize a double variable payRate to 12.50.

e.Copy the value of an int variable firstNum into an int variable tempNum.

f. Swap the contents of the int variables x and y. (Declare additional variables, if necessary.)

g.Suppose x and y are double variables. Output the contents of x, y, and the expression x + 12 / y - 18.

h. Declare a char variable grade and set the value of grade to 'A'.

i. Declare int variables to store four integers.

j.Copy the value of a double variable z to the nearest integer into an int variable x.

4. Write C++ statements to do the following:

a.Declare int variables num1 and num2.

b.Prompt the user to input two integers.

c. Input the first number in num1 and the second number in num2.

d.Output num1, num2, and 2 times num1 minus num2. Your output must identify each number and the expression.

5. Evaluate the following expressions.

a.28 - 3 + 6

b.6 / 5

c.3 * 6 / 2 - 15

d.4 - 6 % 11

e.37 / 4.0

f.15 + 18 % 2 - 20 / 6

h.32 % 12 + 6 - 36 / 5 * 8

i.5 / 9 * (32.6 - 4.5)

j.18.0 + 5.0 * 3.0 /4.0

6. Suppose you have the following variable declarations:

d.double w = 3.5

Evaluate each of the followng statements, if possible. If it is not possible, state the reason (assume the statements are independent of each other):

a.(x + y) % y

b.x % y - w

c.(y + z) / w

d.x * z % y + w

e.(x % y) * z

f.(x * y % z) - w

g.x % (y + z)

h.(x % y + z) / w

Part 2

1. Suppose a and b are int variables, c is a double variable, and a = 32, b = 16, and c = 4.5. What is the output of the following statements?

a.cout << a - b * c << endl;

b.cout << a / 2 - c << endl;

c.cout << a / static_cast<double>(b) + 3.5 * c << endl;

d.cout << 62 % 28 + 6.3 + a / (c + 0.5) << endl;

e.cout << 5 - static_cast<int>(c) % 3 + a - b << endl;

f.cout << 22.5 / 2 + 14.0 * 3.5 + 28 << endl;

h.cout << 2 / (c - static_cast<int>(c)) << endl;

2. Preprocessor directives begin with which of the following symbols:

a.*

b.#

c.$

d.!

e.None of these.

3. Suppose a, b, and c are int variables and a = 5 and b = 6. What value is assigned to each variable after each statement executes? If a variable is undefined at a particular statement, report UND (undefined).

Explanation / Answer

part 2
1.
a. 0.50; b. 24.50; c. 37.6; d. 8.3; e. 10; f. 38.75

part 1
4
a. int num1;
int num2;
b. cout << "Enter two numbers separated by spaces." << endl;
c. cin >> num1 >> num2;
d. cout << "num1 = " << num1 << "num2 = " << num2
<< "2 * num1 - num2 = " << 2 * num1 - num2 << endl;

part 1-
1
a. x *= 2;
b. x += y - 2;
c. sum += num;
d. z *= x + 2;
e. y /= x + 5;

part 2
3
a b c
a = (b++) + 3; 9 7 und
c = 2 * a + (++b); 9 8 26
b = 2 * (++c) – (a++); 10 45 27