=========================preview======================
(comp102)[2007](f)final~2752^_38898.pdf
Back to COMP102 Login to download
======================================================
THE HONG KONG UNIVERSITY OF SCIENCE AND TECHNOLOGY
Department of Computer Science

COMP 102: Computer and Programming Fundamentals I
Fall 2007 Final Examination

Date: December 15, 2007

This exam contains 8 questions on 16 pages. Please count the pages.
You have 3 hours to complete this exam.

Problem Your points Max points Problem Your points Max points
1 10 5 20
2 10 6 10
3 14 7 10
4 14 8 12

Subtotal 48 Subtotal 52
Your total points

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 Universitys regulations governing academic integrity.
Signature: 1. [10 marks total] Multiple choices. Circle the letters on the left for ALL the correct answers.
a) Which of the following function results in 8.0?
A. floor(8.5)
B. max(8.5, 8.0)
C. pow(8.5, 3.4)
D. ceil(8.5)
b) When you pass an array to a function, the function receives __________.
A. the length of the array
B. the reference of the array
C. a copy of the first element
D. a copy of the array
c) Which of the following function declaration is correct?
A. int f(int a[][], int rowSize, int columnSize);
B. int f(int a[][3], int rowSize, int columnSize);
C. int f(int a[3][], int rowSize, int columnSize);
D. int f(int[][] a, int rowSize, int columnSize);
d) Which of the following could be used to invoke function fin part c)?
A. f({{1, 2}, {3, 4}, {5, 6}}, 2, 3);
B. int a[2][3]; f(a[2][3], 2, 3);
C. int a[2][3]; f(a[][], 2, 3);
D. int a[2][3]; f(a, 2, 3);
e) Which of the following statements are true?
A. A recursive function is invoked differently from a non-recursive function.
B. Every recursive call reduces the original problem, bringing it increasingly closer to a base case until it becomes that case.
C. Every recursive function must have a base case or a stopping condition.
D. Every recursive function must have a return value.
E. A recursive function can always be replaced by a non-recursive function.


2. a. [10 marks total] Arrays. (2 marks) Suppose array ais defined as follows. int a[10] = {1, 2, 3}; What is a[0] - a[2]? Answer: ____________________________________________________________
b. (2 marks) Consider the following statements. int numbers[][5] = {{1}, {1, 2}, {1, 2, 3}}; What is the size of the array? Answer: ________________ rows, ________________________ columns
c. (2 marks) Suppose array Sis defined as follows: int S[3][4] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; What is S[1][2] C S[2][1]?
Answer: ____________________________________________________________
d. (4 marks) Suppose structure SRis defined as follows: struct SR { int homework[2]; int midterm; int final; }; And you have defined an array of SR as follows: SR mylist[6]; How t