=========================preview======================
(comp102)[2006](sum)final~PPSpider^_10117.pdf
Back to COMP102 Login to download
======================================================
Department of Computer Science and Engineering, HKUST
Summer Programming Course 2006
Final Examination
Date: Aug 18, 2006
Time: 14:00 C 17:00
Personal Information:
Name
Student ID (summerXX)
Email
Department (CS/CPEG)
Instructions:
1) All questions must be answered.
2) This is a closed-book, closed-note exam.
3) Calculator and any other electronic devices are disallowed in this exam.
4) Your answer will be graded on efficiency, clarity, correctness and precision.
5) Answer the questions in the space provided. Rough work should be crossed out.
6) Your answer should base on the g++ run on the Linux machines in CS Lab 2.
7) You should assume all standard libraries in the given code are included properly.
Marks:
Question
SubTotal
Question
SubTotal
1
/ 5
7
/ 9
2
/ 4
8
/ 15
3
/ 6
9
/ 15
4
/ 5
10
/ 16
5
/ 5
11
/ 15
6
/ 5
Total
/ 100
Question 1: Given the following code segment, when will the function in_stream.eof() return true? You may choose more than one choices. (5 marks)
Choices:
a. When in_stream.get(ch) reads the last character of the file.
b. When in_stream.get(ch) reads the 65536th character of the file, which is the maximum size of an ordinary text file.
c. When in_stream.get(ch) reads a special indicator \0
d. When in_stream.get(ch) reads a special indicator EOF
Answer to Question 1:
Question 2: What will be printed by the following program? (4 marks)
Answer to Question 2:
Text Box: namespace teamA {
int fire(int num) { return num*3; }
int bomb(int num) { return num*2; }
}
namespace teamB {
double fire(double num) { return num*5.0; }
double bomb(double num) { return num; }
}
using teamA::fire;
using teamB::bomb;
int main() {
cout << fire(4) << endl;
cout << bomb(4) << endl;
return 0;
}
Text Box: int main() {
ifstream in_stream;
char ch;
in_stream.open("file1.dat");
in_stream.get(ch);
while (!in_stream.eof()) {
cout << ch << endl;
in_stream.get(ch);
}
in_stream.close();
return 0;
}
Question 3: What will be printed by the following program? (6 marks)
Answer to Question 3:
Text Box: class Phone {
public:
Phone () { cout << "Phone's constructor" << endl; }
~Phone () { cout << "Phone's destructor" << endl; }
};
class Person {
public:
Person() { cout << "Person's constructor" << endl; }
~Person() { cout << "Person's destructor" << endl; }
};
class Student : public Person {
private:
Phone phone;
public:
Student() { cout << "Student's constructor" << endl; }
~Student() { cout << "Student's destructor" << endl; }
};
int main() {
Student* p = new Student;
delete p;
return 0;
}
For questions 4-6, what is the output of the program, if ther