finw2011_soln

# finw2011_soln - University of Waterloo Final Examination...

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

Term: Winter Year: 2011 Student Name ______________________________________________________________________ Signature: ___________________________________________________________________________ UW Student Number: ________________________________ SUPP/DEFERRED EXAM _______ Course Abbreviation and Number GEN E 121 (Mech Eng C++/RobotC) Course Title Digital Computation Section(s) 001 Instructor C. Hulls Date of Exam Saturday April 16, 2010 Time Period Start time: 9:00a.m. End time: 11:30a.m. Duration of Exam 2.5 hours Number of Exam Pages (including this cover sheet) 9 Exam Type Special Materials Additional Materials Allowed ONE 8.5 inch x11 inch sheet marked on BOTH sides Notes: No electronic devices including NO CALCULATORS You can assume for any programs that any necessary #include s have been written. If you need to make any assumptions to formulate your solution, state your assumptions clearly. Answer all questions in the space provided. If you require additional space, write on the back of the opposite page and indicate this clearly. Unless specified in the question, you do not need to include error checking. Questions are to be answered using C++ except where indicated as RobotC using Marking Scheme: Question Maximum Mark Mark 1. 10 2. 10 3. 12 4. 28 5. 30 Total 90 University of Waterloo Final Examination

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

View Full Document
ID___________________________ Mech Eng GENE 121 (C++/RobotC) Page 2 of 9 1. Short Answer [10 Marks] (a) [3 Marks] Complete the statements below. i. double a[10] declares an array of size ___10______. ii. 11001 in binary is __25____ in base 10. iii. time100[1] measures elapsed time in __0.1 seconds or 100 milliseconds __. (b) [3 Marks] What is output by void f(int* p1, int* p2) { if (*p1 < *p2) *p1 *= 2; else *p2 = 1; } int main() { int x = 3, y = 4; f(&x,&y); cout << x << "," << y << endl; int* p1 = &x; int* p2 = p1; f(p1,p2); cout << x << "," << y << endl; return 0; } 6,4 1,4 (c) [4 Marks] What is output by int mixer(int & a, int & b, int c) { c *= a; b = a++; return c; } int main() { int a = 3, b = -4, c = 1; cout << mixer(b,c,b) << endl << a << endl << b << endl << c << endl; return 0; } 16 3 -3 -4
ID___________________________ Mech Eng GENE 121 (C++/RobotC) Page 3 of 9 2. Errors [10 Marks] (a) [6 Marks] The code below has six errors. Identify them, and indicate how you would correct them. Marks will be deducted for incorrectly identified errors. The code converts polar coordinates (r, θ) to Cartesian coordinates (x, y). void polar2cart(double r , double theta , double & x , double & y ) ; { x = r * cos( theta ) ; //convert theta to radians y = r * sin ( theta ) ; //convert theta to radians } int main( ) { do { cout << "Enter radius and angle (0 to 360 degrees)" << endl; double radius , angle ; //scope issue. These need to be declared outside the loop. cin

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 ]}

### Page1 / 9

finw2011_soln - University of Waterloo Final Examination...

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

View Full Document
Ask a homework question - tutors are online