Final_07_spring

Final_07_spring - May 29, 2007 COMP 102 - Final Exam Page 1...

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

View Full Document Right Arrow Icon
May 29, 2007 COMP 102 -- Final Exam Page 1 of 14 THE HONGKONG UNIVERSITY OF SCIENCE AND TECHNOLOGY Department of Computer Science COMP 102: Computer and Programming Fundamentals I Spring 2007 Final Examination Date: May, 29, 2007 This exam contains 9 questions in 14 pages. Please count the pages. You have 3 hours to complete this exam. Problem Your point s Max point s Problem Your point s Max point s 1 5 6 16 2 13 7 20 3 6 8 10 4 8 9 10 5 12 Subtotal 44 Subtotal 56 Your total points: 100 Please identify yourself: Lecture/Lab section Name Student ID I have neither given nor received any unauthorized aid during this examination. The answers submitted are my own work. I understand that sanctions will be imposed, if I am found to have violated the University’s regulations governing academic integrity. Signature:
Background image of page 1

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

View Full DocumentRight Arrow Icon
May 29, 2007 COMP 102 -- Final Exam Page 2 of 14 1 [5 marks] Consider the following enum definition and C++ statements : enum weekdays {sun,mon,tue,wed,thur,fri,sat}; weekdays day; For each of the following statement, mark it with “True” if it is correct or “False” if it is incorrect. (Please notice that compile warning is treated as correct.) a) day = fri; Answer: ___________ b) day = 3; Answer: ___________ c) day = (weekdays)1; Answer: ___________ d) int i = day; Answer: ___________ e) bool b = day; Answer: ___________
Background image of page 2
May 29, 2007 COMP 102 -- Final Exam Page 3 of 14 2. [13 marks total] a) [6 marks] Consider the following function of binary search, int binary_search(char data[],// input: array int size, // input: array size char value // input: value to find ) // output: index of value if found { // -1 if value is not found int lower, middle, upper; // indexes to the array lower = 0; upper = size - 1; while (true) { for (int i = lower; i <= upper; i++) cout << data[i]<< ' '; cout << endl; middle = (lower + upper) / 2; if (data[middle] == value) return middle; else if (lower >= upper) return -1; else if (value < data[middle]) upper = middle - 1; else lower = middle + 1; } } Assuming char list[20]="12345678"; What are the outputs of the following function calls? (Please use to indicate a white space ) cout << binary_search(list, 8, '7') << endl; Answer: __________________________________________________________________ __________________________________________________________________ __________________________________________________________________ __________________________________________________________________ cout << binary_search(list, 8, '0') << endl; Answer: __________________________________________________________________ __________________________________________________________________ __________________________________________________________________ __________________________________________________________________ __________________________________________________________________
Background image of page 3

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

View Full DocumentRight Arrow Icon
May 29, 2007 COMP 102 -- Final Exam Page 4 of 14 b) [7 marks] What is the output of the following program? (Please use to indicate a white space )
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 08/07/2011 for the course COMP 102 taught by Professor Daniel during the Spring '08 term at HKUST.

Page1 / 14

Final_07_spring - May 29, 2007 COMP 102 - Final Exam Page 1...

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