{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

f2010fin

# f2010fin - University of Waterloo Final Examination Term...

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? 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. 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? 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; }
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; }

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

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern