Question
Consider the following scenario of a class Person. A Person class has a Name, ID, Address and has functions of change the address and profile
Consider the following scenario of a class Person. A Person class has a Name, ID, Address and has functions of change the address and profile display. (Hint: Composition is not applied)
Two classes are derived from this class person. 1) Student 2) Employee.
The student class has a course number, classes attended, year (freshman=1, sophomore=2 and so on), and functions to change course and profile display.
The employee class has a Date of joining and date of promotion.
The employee class further has two child classes 1) Faculty 2) Admin.
Faculty class has a course number, classes taught, Rank (AP, lecturer etc) and a function to display profile.
Admin class has number of projects worked on and a display profile function.
Answer the question based on this scenario.
Question 7: [CLO2- 8 marks]
a) Should destructors in the base class Person be declared virtual? Explain why or why not. [2 marks]
b) Can we make a constructor virtual? Why or why not? (Explain with reference to VPTR) . [1 mark]
c) Can we make Person class as abstract class? If yes, how? If no, why? [1 mark]
d) What happens if we do not make a constructor of an abstract class. Explain. [1 mark]
e) Is is possible to make promote function as virtual? Can this class be made abstract? Justify your answer. [1 mark]
f) Should we define a destructor of an abstract class? Justify your answer with proper reasoning. [1 mark]
g) Why was there a need to define virtual functions? Explain an issue/trouble faced in inheritance that is only resolved by making functions virtual? [1 mark]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started