Take Home Practice quiz_Sol

Take Home Practice quiz_Sol - Take Home Practice quiz 1)...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Take Home Practice quiz 1) Correct the following program. Mark the mistake and write the correction in front of it. (10 Pts.) (there are 10 errors) #include (iostream) <iostream> constant pi = 3.14 ; const main() { int main() int x = 8.9 ; int x = 8 ; or float x = 8.9 real num = 43 ; float num = 43 ; or double num = 43 ; setprecision(3); cout << setprecision(3) and needs #include <iomanip> setw(10); cout << setw(10) ; cin >> x << num ; cin >> x >> num ; cout << “Num =“, x ; cout << “Num = “ << num ; x = num % 3 + x ; num is float type and % does not work with real numbers x = ++num / 0 ; Division by 0 not allowed return 0 ; } Trace Table 2) Trace the following program Segments and show the output. x y z int x = 3, y = 5, z = 0 ; 3 5 0 z += x * y + 2.3 ; 17 z *= --x ; 2 34 y++ ; 6 z += x - y % 3 ; 36 cout << x <<” ” << y <<” ” << z << endl ; 8 output: 2 6 36 Trace table: num num<=10 num>=0 int num = 20; 20 if(num <= 10) No if(num >= 0) Never checked cout<<"Num is between 0 and 10";
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/01/2009 for the course CS 101 at USC.

Page1 / 4

Take Home Practice quiz_Sol - Take Home Practice quiz 1)...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online