f2010fin_soln

f2010fin_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: 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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
Initials: _______________________ ID Number: ___________________________ GENE 121 4 of 13 2. Arrays [7 Marks Total]
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.

This note was uploaded on 04/01/2012 for the course GENE 121 taught by Professor Smucker during the Winter '11 term at Waterloo.

Page1 / 13

f2010fin_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