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

1. Given the following expressions, what value would they have in a C++ program?

ID: 3637458 • Letter: 1

Question

1. Given the following expressions, what value would they have in a C++ program?
a. 13 / 4
b. 2 + 12 / 4
c. 21 % 5
d. 3 - 5 % 7
e. 17.0 / 4
f. 8 - 5 * 2.0
g. 14 + 5 % 2 - 3
h. 15.0 + 3.0 / 2.0

2. Given the following variable declarations:

int num1 = 10, num2 = 20, newNum = 30;
double x = 5.0, y = 8.0;

Determine which of the following assignment statements are valid. For each invalid statement, explain why it is invalid. Assume that each statement immediately follows the above variable declarations.

a. num1 = 15;
b. num2 = num1 - 18;
c. num1 = 5; num2 = 2 + 6; num1 = num2 / 3;
d. num1 + num2 = newNum;
e. x = 12 * num1 - 15.3;
f. num1 * 2 = newNum;
g. x / y = x * y;
h. num2 = num1 % 2.0;
i. newNum = static_cast<int> (x) % 5;
j. x = x + 5;
k. newNum = num1 + static_cast<int> (4.6 / 2);

Explanation / Answer

From Line 1, n = 12; is a not correct declaration of the variable. Here the data-type was not specified. Thus, the correct declaration is int n = 12; From Line 2, char letter = ; is not a correct declaration of the variable. In this case, either the symbol should be removed or the variable should be initialized with some value. So, the correct declaration would be either char letter; or char letter = 'A'; From Line 3, int one = 5, two; is correct declartion From Line 4, double x, y, z; is correct declartion 5. a. x = 2, y = 5, z = 6 b. x + y = 7 c.Sum of 2 and 6 is 8 d. z / x = 3 e. 2 times 2 = 4 I hope this will helps to You !