=========================preview======================
(COMP152)[2010](s)final~=4hh9b08kvv^_34806.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

Spring 2010
Final Examination

Instructor: Gary Chan (L1) / Dit-Yan Yeung (L2) / Huamin Qu (L3)

Date: Monday, 24 May 2010
Time: 8:30am C 11:30am
Venue: Sports Hall

.
This is a closed-book examination. However, you are allowed to bring with you a piece of A4-sized paper with notes written or typed on both sides for use in the examination.

.
Your answers will be graded according to correctness, ef.ciency, precision, and clarity.

.
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 25 single-sided pages. Please check that all pages are properly printed before you start working.


Student name: English nickname (if any): Student ID: Email: Lecture session:
I have not violated the Academic Honor Code in this examination (your signature):
Question Your score Maximum score Question Your score Maximum score
1 24 4 15
2 15 5 15
3 15 6 16
Total 100

1. Short Questions (24 points total)
(a) [4 points] Consider the following codes:
#include <iostream> using namespace std;
class Foo { public: explicit Foo(int i) : bar(i) { }
private: int bar; };
void // } f(Foo f) { nothing needs to be done here
int { main() Foo foo1(3); Foo foo2 = 3; Foo foo3 = Foo(f(3); 3); // // // // line line line line 1 2 3 4
return 0;

}
Which line(s) in main() contains compilation errors? Brie.y explain why.

(b)
[4 points] Consider a stack with numbers from top to bottom 1 2 3 4 5. We pop the stack 5 times; for each number popped, we push it into an originally empty queue. After that, we dequeue these numbers one by one by pushing each of the dequeued number back into the stack.

List the resultant numbers from top to bottom in the stack.

(c)
[4 points] Consider the following codes which compile without error:


#include <iostream>
using namespace std;

class foo {
public:

foo operator--(int) {
cout << "1st --\n";
return *this;

}
foo& operator--() {
cout << "2nd --\n";
return *this;

}
};

int main()
{
foo f1;
f1--;
--f1;
return 0;

}
What is the output of the program?
(d) [4 points] Consider the following program which compiles without error:
#include <iostream>
using namespace std;

class B
{
public:

virtual .B() { cout << "Bs destructor" << endl; } void fun() { cout << "Bs fun" << endl; } };
class D : public B
{
public:

.D() { cout << "Ds destructor" << endl; } void fun() { B::fun(); cout << "Ds fun" << endl; } };
int main()
{
B *b = new D;
b->fun();
delete b;

return 0;
}

What is the output of this program?
(e) [4 points] The following are the codes for insertion sort as discussed