2nd SEMESTER 2021/22 Resit Exam
Undergraduate – Year 2
C++ Programming and Software Engineering II
Exam Duration: 2 Hours
INSTRUCTIONS TO CANDIDATES
1、 This is an open book resit exam. Please complete the exam independently and honestly.
2、 The total marks available are 100.
3、 Answer all questions in the answer booklet and submit it to LMO. There is NO penalty for providing a wrong answer.
4、 The duration is 2 hours.
Q3 | a) |
Read the following codes. Fill in the blanks based on the output of the code fragment. | Total 20 | |
i) | for (int k = 0; k < 9; ) cout << ++k << ‘\t’; Output is: 1 5 9 | (5) | ||
ii) | int k = 0; while (k < 10){ cout << k++; if (k%4==0) ; cout<<’;’; }
Output is: 0;1;2;3 | (5) |
b) | Given the following class definitions and main function: | ||
class clA { private: int a; public: virtual void print(){ cout << "base class\n"; } ~clA(){ cout << "base class destructor\n"; } }; | |||
class clB { public: int b; void print(){ cout << "print derived class\n"; } ~clB(){ cout << "derived class destructor\n"; } }; | |||
void main(){ clB obj; clA* ptr3 = &obj; ptr3->print(); } | |||
(1) Write down one line of correct code to fix the compiling error of the program by updating the definition of class clB. (3) (2) Write down what would the main function print out? (3) (3) Write down the explanation of the output result of the program by using OOP concept. (4) | (10) |