{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Take Home Practice quiz_Sol

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

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

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"; else //Match if(num >=0) never checked cout<<"Num is greater than 10"; Output: nothing is printed int alpha = 0, beta; Trace table: cin >> beta ;

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern