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.
Q4 |
An abstract class Shape is defined as follows: | Total 20 |
class Shape{ public: virtual void print() = 0;//print the shape name virtual double area() = 0; //return the area of a shape }; An incomplete class Rectangle is defined as follows: class Rectangle: Shape { private: double a, b; public: Rectangle(double x);//a square Rectangle(double x, double y); double area(); void print(); bool operator >=(Rectangle r); bool operator <=(Rectangle r); }; | |||
a) | Complete the definition of the two constructors of class Rectangle. | (5) | |
b) | Complete the definition of the overriding functions of class Rectangle. | (5) | |
c) | Produce the complete functions for the overloading operators. | (5) | |
d) | Write a main() function to test the class Rectangle and Shape. In the main() function, the following are expected to be tested: the two constructors, shape type output, Rectangle’s area and overloading operators. | (5) |