S10Final_Soln

S10Final_Soln - University of Waterloo Final Examination...

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

View Full Document Right Arrow Icon
Term: Spring Year: 2010 Student Name: ________________________________________ Student ID Number: ___________________________________ Course Abbreviation and Number GENE 121 (Mech Eng C++/RobotC) Course Title Digital Computation Section(s) 001 Instructor Rajnish Bassi Date of Exam August 7, 2010 Time Period Start time: 9:00 am End time: 11:30am Duration of Exam 2.5 hrs Number of Exam Pages 12 (including this cover sheet) Exam Type Special Materials Additional Materials Allowed ONE (8.5X11) formula sheet Writing instruments Notes: No electronic devices including NO CALCULATORS You can assume for any program that any necessary #include s have been written. If you need to make any assumption 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. Marking Scheme: Question Maximum Marks Mark 1 10 2 10 3 20 4 10 5 25 6 25 Total 100 University of Waterloo Final Examination
Background image of page 1

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

View Full Document Right Arrow Icon
Page 2 of 12 1. Short Answer [10 marks] a) [4Marks] Answer true (T) or false (F) for each of the following __ F __ declaring arrays with more than two dimensions results in compile-time error __ F __ all C++ operators are evaluated from left to right __ T __ parameters passed by value to a function are considered as local variables __ T __ theoretically, ultrasonic sensor can detect obstacles within the range of 0-255 cm b) [3 Marks] What will be the output? int valRef (int &i, int j, int &k) { i = j * k; return ++j; } int valRef (int &i, int &j, double k) { i = j * k; return ++j; } int main() { int i, j = 2; double k = 2; i = valRef (j, j, k); cout << i << j; i = valRef (j, j, j); cout << i << j; return 0; } 55625
Background image of page 2
Page 3 of 12 c) [3 marks] What will be the output? int main() { int a[5] = {3, 5, 3, 6}, b = 2, c = 3; int *q = &b; *q = *(a+1)**q; c = (*a+1)**q; cout << b << " " << c ; return 0; } 10 40 2. Functions [10 marks] Write a function that receives an array of integers sorted in ascending order, the number of array elements, and another integer. The function must insert the integer into the correct position in the array. If the integer is already in the list, it should not be added again. You may assume that the array has enough room for the extra integer. void Insert(int a[], int &n, int x) { int i,k; bool found=false; for (i=0; i<n && !found; i++) { if (x<a[i]) //insert in the middle of the array { for (k=n; k>i; k--) a[k]=a[k-1]; a[i]=x; n++; found=true; } else if (i=n-1 && x>a[i]) { a[n]=x; n++; } else if (x==a[i]) found=true; } } OR void Insert(int a[], int &n, int x) { int i=0; k; while (i<n && a[i]<x) i++; if (i<=n) for (k=n; k>i; k--) a[k]=a[k-1]; a[k]=x; n++; }
Background image of page 3

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

View Full Document Right Arrow Icon
Page 4 of 12 3. Thermocouple Data Analysis [20 marks] The diagram shows a metal plate used in a thermodynamic experiment. There are 500 thermocouples (electric thermometers) fastened to the plate - each one measuring the
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 12

S10Final_Soln - University of Waterloo Final Examination...

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

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