Question: Solve every question using the precedence and associative rules. Assume the following rules of associativity and precedence for expressions: Precedence Highest + , - *,

Solve every question using the precedence and associative rules.

Assume the following rules of associativity and precedence for expressions: Precedence Highest + , - *, /, not &, mod - (unary) = , /= , < , > and <= , >= Lowest or, xor Associativity: Left to right

[1] Show the order of evaluation of the following expressions by parenthesizing all subexpressions a. a * b - 1 + c / d + e b. a * (b - 1) / c mod d mod f c. (a - b) / c & (d * e / a - 3) d. -a or c = d and e or f e. a > b xor c or d <= 17 f. -a + b - c / e

[2] Show the order of evaluation of the expressions assuming that there are no precedence rules and all operators associate left to right.

a. a * b - 1 + c / d + e b. a * (b - 1) / c mod d mod f c. (a - b) / c & (d * e / a - 3) d. -a or c = d and e or f e. a > b xor c or d <= 17 f. -a + b - c / e

[3] Write a C/C++ program that has the following statements: int a, b; // global

a = 10; b = a + fun(); cout << "With the function call on the right, "; cout << " b is: " << b << endl; a = 10; b = fun() + a; cout << "With the function call on the left, "; cout << " b is: " << b << endl; return 0;

Define fun to add 10 to a. Execute the program and explain the results.

[4] Rewrite the following code segment using a multiple-selection statement in C/C++/Java:

if ((k == 1) || (k == 4)) j = 2 * k - 1

if ((k == 8) || (k == 5)) j = 3 * k + 1

if (k == 3) j = 4 * k - 1

if ((k == 2) j *= k

if ((k == 6) || (k == 7) || (k == 9)) j = k - 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!