Presentation is loading. Please wait.

Presentation is loading. Please wait.

Solution of Mid. Term 2009 Consider the following C++ declarations and assignments. int i, j, k ; float x, y ; char c ; bool test ; i = 35 ; j= 5 ; k =

Similar presentations


Presentation on theme: "Solution of Mid. Term 2009 Consider the following C++ declarations and assignments. int i, j, k ; float x, y ; char c ; bool test ; i = 35 ; j= 5 ; k ="— Presentation transcript:

1 Solution of Mid. Term 2009 Consider the following C++ declarations and assignments. int i, j, k ; float x, y ; char c ; bool test ; i = 35 ; j= 5 ; k = 2 ; x = 10.0 ; y = 2.5 ; c = ‘p’; test = true ; For each of the following expressions, state whether it is valid or not. If an expression is valid, evaluate it. د / محمد ناجى

2 x – x / y – y * k + i / k + 8 * j + 6 123 4 5 6 7 8 9 1) 4.0 2) 5.0 3) 17 4) 40 5) 6.0 6) 1.0 7) 18.0 8) 58.0 9) 64.0 1)

3 i / k / j + x >= (i + j) % int (x + y) * k 12 3 4 5 6 7 8 9 (1) 40 (2) 12.5 (3) 13 (4) 17 (5) 3 (6) 1 (7) 2 (8) 13.0 (9) true 2)

4 i / y / j / k * x + float( i ) / ( j + k ) * y – x 12 3 4 5 6 7 8 9 10 1)7 2)35.0 3)14.0 4)2.8 5)1.4 6)14.0 7)5.0 8)12.5 9)26.5 10)16.5 3)

5 (i / k== x+y+j ) || (i+x <=j+k ) || ( c == 's' ) 1 1) 172) 12.53) 17.54) false5) 45.0 6) 77) false8) false9) false 2 3 4 56 7 8 9 10 10) false 4)

6 (-- i) / (++k) % ( j++) + x / y – i * j + 7 * k 123 6 11 9 10 5 4 78 1) 34 2) 3 3) 5 4) 11 5) 1 6) 4.0 7) 170 8) 21 9) 5.010) -165.011) -144.0 6)

7 !(test || (i / j % k > 10 )) && !(test) 1 2 3 4 5 6 7 1) 7 2) 1 3) false 4) true 5) false 6) false 7) false 7)

8 i / int ( x +y ) / k % j + i % k * y +10 1 2 5 6 7 1) 12.52) 12 3) 2 3 4 8 9 4) 1 5) 16) 17) 2.5 8) 3.59) 13.5 10)

9 ((x+y > j+k) || (c == 'w')) && test 12 3 4 5 6 1) 12.52) 73) true4) false5) true6) true 11)

10 x + 5 * y + i * k % x + i – y / j + 20 Invalid. The right operand of the mod (x) is float ( x + j + 5 > i – k ) && ( y + k < ( i + x ) % k ) && test Invalid. The left operand of the mod operator (i + x) is float 5) 12) !( c = 'p' ) || (x + 3 * i + j >= i – y) && test 8) x * i – x / y – w * k / k + j / 15 + 3 * y * j Invalid. W is undeclared 9) Invalid. The equal sign in (c = ‘p’) must be ==

11

12 Start Read x S1 = 4, s2 = x i = 2 Stop i ≤ 15 T F i = i + 1 S3 = 0, i = 2 i ≤ 26 i = i + 1 Print S1, S2, Z, S3 T F


Download ppt "Solution of Mid. Term 2009 Consider the following C++ declarations and assignments. int i, j, k ; float x, y ; char c ; bool test ; i = 35 ; j= 5 ; k ="

Similar presentations


Ads by Google