1 / 12

Solution of Mid. Term 2009 Consider the following C++ declarations and assignments.

د / محمد ناجى. 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 ;

cedric
Télécharger la présentation

Solution of Mid. Term 2009 Consider the following C++ declarations and assignments.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 1) 4 1 2 3 5 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 6 7 8 9

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

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

  5. (i / k== x+y+j ) || (i+x <=j+k ) || ( c == 's' ) 4) 1 2 5 6 8 3 7 4 9 10 1) 17 2) 12.5 3) 17.5 4) false 5) 45.0 6) 7 7) false 8) false 9) false 10) false

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

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

  8. 10) i / int ( x +y ) / k % j + i % k * y +10 6 1 7 2 3 4 1) 12.5 2) 12 3) 2 5 5) 1 6) 1 7) 2.5 4) 1 8 8) 3.5 9) 13.5 9

  9. ((x+y > j+k) || (c == 'w')) && test 11) 1 2 4 3 5 6 1) 12.5 2) 7 3) true 4) false 5) true 6) true

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

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

More Related