Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Lab 04 - Operators

Exercise 1.

For the operations in the table predict what answer you would expect to see and fill in the appropriate column.

Operation

Predicted Result

Actual Result

17/5 + 2

 

 

5 * (3+6) / 2

 

 

5 * 3 + 6 / 2

 

 

36 + 4 * 2 – 17

 

 

25 % 10 + 7

 

 

25 % 2 / 5

 

 

Write a simple program(s) to confirm the actual result of these operations.  If your predicted results do not match the actual results make sure you understand why.  

Exercise 2.

Consider the following piece of code :

bool a , b , c , d , e;

short w, x, y, z;

w = 1;

x = 5;

y = 10;

z = 20;

What would be the result of the following operations :

• a = (x > y);

• b = (w < 5);

• c = (x > y) && (w > z);

• d = (x > y) || (w > z);

• e = !((x + y) > z);

Variable

Predicted Final Value

Actual Final Value

a

 

 

b

 

 

c

 

 

d

 

 

e

 

 

Assuming that the above operations have all run what would be the final values of all the variables after the following code had run ?

a = !d;

b = (y--) > (w++);

z = y / x;

d = ((y+10) > (z * 30)) && (w==3);

Variable

Predicted Final Value

Actual Final Value

a

 

 

b

 

 

c

 

 

d

 

 

e

 

 

w

 

 

x

 

 

y

 

 

z

 

 

Write a program to confirm your results.  Again ask for help if any don’t match and you don’t know why.