=========================preview======================
(COMP104)[2009](f)final~ee_pax^_10131.pdf
Back to COMP104 Login to download
======================================================
For T.A. use only

COMP 104 Final Exam -Fall 2009 -HKUST

Date: Friday, December 18, 2009 Time allowed: 3 hours, 16:30C19:30 Instructions: (1) This is a closed-book, closed-notes examination.
(2)
There are 10 questions on 15 pages.

(3)
There are also 3 pages of scrap paper that will not be graded.

(4)
First write your name and ID in the space provided below.

(5)
Then answer the questions in the space after Answer:, unless otherwise stated by the speci.c problem.

(6)
You must answer all questions in black or blue ink (no pencils).

(7)
All codes described in the questions are ANSI C++ compliant.


Student Name
Student ID

For T.A. use only
Problem Score
1 / 10
2 / 15
3 / 6
4 / 6
5 / 8
6 / 7.5
7 / 7.5
8 / 14
9 / 14
10 / 12
Total / 100

Problem 1 [10 points] True or false questions

Indicate whether the following statements are true or false by circling T or F. You get 1 point for each correct answer, .1 for each wrong answer, and 0 if you do not answer. Any negative scores for the entire problem will be upgraded to zero. Remark: Statistically speaking, guessing does not help if you do not know the correct answer.
TF (a)
. When the member functions of a class are de.ned outside the class de.nition, each function name must be prepended with the class name and the special class scope operator :: .
FThe body of a while loop always executes at least once.
T . (b)
F
T . (c) There must be at least ONE return statement in the body of a C++ function.
TF (d)
. The following code outputs true. (Assumption: char consists of 1 byte and int consists of 4 bytes.)
int *p = new int [5];
int *q = new char [10];
cout . ( sizeof(p) == sizeof(q) );

FThe runtime error segmentation fault is due to memory leaks in your program.
T . (e)
TF (f)
.
In C++, the elements of a multi-dimensional array are stored in row-major order (i.e., they are stored in memory row by row).

.
A character string in C++ is an array of characters ending with \0.

.
The value (&a[12]-&a[10]) is always greater than zero.

.
It is possible to have a non-constant pointer to a constant array element.


TF (g)
TF (h)
TF (i)
Fcauses the innermost enclosing loop to exit, while break causes the remainder of the current loop iteration to be skipped.
T . (j)
Problem 2 [15 points] Multiple choice questions

Circle the number to the left of the correct answers. Note that there may be zero, one, or more correct answers per multiple choice question. Each question is worth 3 points, graded as follows:
.
Circle no answers if there are no correct answers: 3 points

.
Only circle all of the correct answers: 3 points

.
Only circle some of the correct answers: 1 points

.
Circle any incorrect answer: 0 points (even if you circled some correct answers)


(a) Given the following variables, which of the following are eva