=========================preview======================
(COMP104)final_sol_07f.pdf
Back to COMP104 Login to download
======================================================
For T.A. use only
COMP 104 Final Exam -Fall 2007 -HKUST
Date: Wednesday, December 19, 2007 Time allowed: 3 hours, 8:30C11:30 AM Instructions: (1) This is a closed-book, closed-notes examination.
(2)
There are 9 questions on 16 pages.
(3)
There are also 2 pages of scrap paper, which you do not need to submit and therefore can be detached from the exam.
(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 SOLUTION KEY
Student ID
For T.A. use only
Problem Score
1 / 5
2 / 16
3 / 5
4 / 6
5 / 12
6 / 12
7 / 8
8 / 16
9 / 20
Total / 100
Problem 1 [5 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). An int array can be a data member of a class.
FThe following code has no compilation errors regardless of the data type of a: (a+2) = 4;
T . (b)
FThe following function declaration has no compilation errors:
T . (c)
int myfunc(int a = 0, int b);
FThe following expression is always true:
T . (d)
(sizeof(double *) != sizeof(bool *))
T
. F (e) The following two code fragments will produce the exact same output:
//code fragment #1:
int a[5][5];
for(int i = 0; i < 5; i++)
for(int j = 0; j < 5; j++)
a[i][j] = i + 5*j;
for(int i = 0; i < 5; i++)
for(int j = 0; j < 5; j++)
cout << a[i][j];
//code fragment #2:
int b[5][5];
for(int j = 0; j < 5; j++)
for(int i = 0; i < 5; i++)
b[i][j] = i + 5*j;
for(int i = 0; i < 5; i++)
for(int j = 0; j < 5; j++)
cout << b[i][j];
Problem 2 [16 points] Multiple choice questions
Circle the number to the left of the correct answers. Note that there may be more than one correct answer per multiple choice question. Each question is worth 4 points, graded as follows:
.
Only circle all of the correct answers: 4 points
.
Only circle some of the correct answers: 2 points
.
Circle any incorrect answer: 0 points (even if you circled some correct answers)
(a) Identify all expressions that are equivalent to &a[3].
(1)
. a+3
(2)
&(a+3)
(3)
*(a+3)
(4)
*(a[3])
(5)
. &((a+2)[1])
(b) Given the following dynamic 2D character array, identify all statements that are correct? (Note that each char occupies 1 byte and each char pointer occupies 4 bytes.)
//dynamic 2D character array
char **b;
b = new char *[4];
for(int i = 0; i < 4; i++)
b[i] = new char[4];
(1) T