{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

S10Mid_Soln - University of Waterloo Midterm Examination...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Page 1 of 10 University of Waterloo Midterm Examination Term: Summer Year: 2010 Student Name:___________________________________________________________ UW Student ID Number:__________________________________________________ Lab Day:___________________________ TA: ___________________________ Course Abbreviation and Number GEN E 121 (Mech C++) Course Title Digital Computation Section(s) 001 Instructor Rajnish Bassi Date of Exam Friday, June 11, 2010 Course Title Start time: 5:00pm End time:7:00pm Duration of Exam 2 hours Allowed Materials: Writing instruments ONE (8.5X11) formula sheet written on ONE side only Disallowed Materials: No electronic devices of any kind No hats or containers such as purses, pencil cases, packsacks Notes: You can assume for any program that any necessary libraries have been imported All questions will be marked for credit If you need to make any assumption to formulate your solution, state your assumption clearly Question Maximum Marks Marks 1. 9 2. 16 3. 10 4. 20 5. 20 6. 25
Image of page 1

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

View Full Document Right Arrow Icon
Page 2 of 10 1. Arithmetic and Boolean Expressions [9 Marks Total …. 3 marks each] Write the output for the following expressions. a) int main ( ) { int i = 5 ; cout << 5 % 4 + 7 / 3.0 + i++ ; } 8.33 b) int main ( ) { float i = 5.0 ; float j ; j = int (i / 3) ; cout << fixed << setprecision (2) << j ; } 1.00 c) int main ( ) { int i ; i = 5 && 8 == 2/3 ; cout << i ; } 0 2. Short Answer [16 Marks Total …. 4, 4, 4, 4] a) What will be the output? int main ( ) { int i = 5 ; if ( i ) cout << "Block 1" ; else if ( i == 5 ) cout << "Block 2" ; else cout << "Block 3" ; } Block 1
Image of page 2
Page 3 of 10 b) What will be the output? (Hint: Carefully observe the syntax) int main ( ) { int x = 5, y = 2 ; if ( x==6 ) ; cout << "Block 1" ; { if ( y==2 ) cout << "Block 2" ; else cout << "Block 3" ; } } Block 1Block 2 c) The following code results in a compile-time error. Indicate how to fix the code.
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern