{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

f2010fin_soln

# f2010fin_soln - University of Waterloo Final Examination...

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

Term: Fall Year: 2010 Student Name (Print) ____________________________________________________________ Signature ______________________________________________________________________ UW Student ID Number _______________________________________________________ Course Abbreviation and Number GENE 121 Course Title Digital Computation Section(s) 001 Instructor C. Hulls Date of Exam Saturday December 11, 2010 Time Period Start time: 9:00 am End time: 11:30 am. Duration of Exam 2.5 hours Number of Exam Pages 13 (including this cover sheet) Exam Type Special Materials Additional Materials Allowed ONE 8.5x11 sheet marked on BOTH sides Notes: No electronic devices of ANY kind. No hats or containers such a purses, pencil cases, packsacks You can assume for any programs that any necessary libraries (e.g. #include <iostream> ) have been included. Answer all questions in the space provided. If you require additional space, write on the back of the opposite page and indicate this clearly. If you need to make any assumptions to formulate your solution, state your assumptions clearly. Marking Scheme: Question Maximum Mark Mark 1. 14 2. 7 3. 8 4. 10 5. 18 6. 22 7. 7 8. 14 Total 100 University of Waterloo Final Examination

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

View Full Document
Initials: _______________________ ID Number: ___________________________ GENE 121 2 of 13 1. Short Answer [14 Marks Total] a. [2 Marks]What is the difference between analog and digital? Analog can have any value between two voltages, for example between 0 and 5V, whereas digital can only have two values: 0 (0V) and 1 (usually 5V). b. [3 Marks] Can a binary search be used on an unsorted list? Explain why or why not by briefly describing, in one or two sentences, how a binary search works. Binary search can not be used on an unsorted list since the algorithm needs to know whether the current test value is more or less than the value we are looking for, and thus we can search in the bottom or top half of the rest of the list. c. [2 Marks] Code to wait for a button push using the Arduino can be written as: while (digitalRead(BUTTON) == LOW); delay(200); How long is the delay in seconds? Why is it included? The delay is 0.2 seconds and is used as a debounce for the push button. d. [2 Marks] What is output by the following code? int main() { string greeting = "Hapoy"; greeting[greeting.size() - 1] = 'p'; string year = "2010"; year = year + '1'; cout << greeting << " " << year << endl; return 0; } Hapop 20101
Initials: _______________________ ID Number: ___________________________ GENE 121 3 of 13 e. [5 Marks] What is output by the following code? void mix(int* x, int* y, int* z) { if (*x > *y) { int* p = x; x = y; y = p; } if (*x > *z) { int q = *x; *x = *z; *z = q; } *x *= -1; *z *= -1; } int main() { int a = 9, b = 7, c = 2; mix(&a, &b, &c); cout << a << " " << b << " " << c << endl; return 0; } 9 -2 -7

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

View Full Document
Initials: _______________________ ID Number: ___________________________ GENE 121 4 of 13 2. Arrays [7 Marks Total] Write a function that receives an array of integers and the number of integers, and returns the smallest even and odd integers. void smallest (int array[], int num, int &even, int &odd) { even=1e10; odd=1e10; for (int i=0; i<num; i++) { if (i % 2 == 0 && array[i]<even) even=array[i]; else if (i % 2 == 1 && array[i]<odd) odd=array[i]; } }
Initials: _______________________ ID Number: ___________________________ GENE 121 5 of 13 3. Structs [8 Marks Total] A C-style struct can be used to store complex numbers: struct Complex { double r, im; }; void scale(Complex & a, double b) { a.r *= b; a.im *= b; } a. How are the parameters a and b passed to the scale function?

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