=========================preview======================
(COMP152)[2010](f)final~=4hh9b08kvv^_45819.pdf
Back to COMP152 Login to download
======================================================
THE HONG KONG UNIVERSITY OF SCIENCE & TECHNOLOGY
Department of Computer Science & Engineering
COMP 152: Object-Oriented Programming and Data Structures
Fall 2010
Final Examination
Instructor: Gary Chan
Date: Tuesday, 21 December 2010
Time: 12:30pm C 3:30pm
Venue: LG1
.
This is a closed-book examination. However, you are allowed to bring with you ONE piece of A4-sized paper with notes written or typed on both sides for use in the exami-nation.
.
Your answers will be graded according to correctness, precision, clarity and ef.ciency.
.
During the examination, you should put aside your calculators, mobile phones, PDAs and all other electronic devices. In particular, all mobile phones should be turned off completely.
.
This booklet has 35 single-sided pages. Please check that all pages are properly printed before you start working.
.
You may use the reverse side of the pages for your rough work or continuation of work.
Student name: English nickname (if any): Student ID: Email:
I have not violated the Academic Honor Code in this examination (your signature):
Question Your score
Maximum score
Question
Your score
Maximum score
1
18
4
17
2
17
5
17
3
16
6
15
Total
100
1. Short Questions (18 points total, 3 points each)
(a) Please brie.y explain the problem(s), if any, of the following functions. If you think that they are correct, just write No problem.
int* fun1(){
int array[]={1, 2, 3, 4, 5};
return array;
}
int fun2(){
int* ptr = new int [10];
return *ptr;
}
(b) You are given the following recursive function:
void fun (int value){
if (value <= 0)
return;
else{
fun (value / 2);
cout << value % 2;
}
}
i. What is the output if fun(12) is invoked?
ii. Brie.y say what the function does or computes.
(c)
Circle the one of the following operators which is not allowed to be overloaded.
i. []
ii. <<
iii. sizeof
iv. new
(d)
Most of the time we can overload an operator either as a member function or a non-member function. There are some operator or operations which can NEVER be over-loaded as a member function, and hence a non-member function is the only choice. Can you give an example of such operator or operation?
(e)
What is the output of the following program?
#include <iostream>
using namespace std;
class A {
public:
A(){ cout << "As constructor"<<endl;}
.A(){ cout << "As destructor"<<endl; }
};
class B {
public:
B(){ cout << "Bs constructor"<<endl;}
.B(){ cout << "Bs destructor"<<endl; }
};
class C: public B {
public:
C(){ cout << "Cs constructor"<<endl;}
.C(){ cout << "Cs destructor"<<endl; }
private:
A a;
};
int main(){
C c;
cout << "========" << endl;
return 0;
}
(f) You are given the following binary search tree:
Draw below the resulting tree after deleting the node 35. (If the tree node is a