c++ question
· Class Person holds
o Two attributes i.e. name and year_of_birth
o A two-argument constructor to initialize its data members with user-defined values
· Class Student has
o Two attributes i.e. studentID and enrolledSemester
o A four-argument constructor to initialize its data members (including inherited data members)
o A function named display() to show the values of all attributes (including inherited attributes)
· Class Employee contains
o Five attributes i.e. employeeID, joiningYear, jobTitle (designation of an employee), courseID, and courseTitle
· Class Administration has
o A parameterized constructor to receive five arguments to initialize inherited attributes from classEmployee (Concerning courseID and courseTitle, only null value is allowed to set for an admin officer) Two functions i.e. setJobTitle(employee) and getJobTitle(employee) to set and get job title of an employee
· Class Academic has
o A parameterized constructor to receive five arguments to initialize inherited attributes from class Employee (Concerning employeeID, joiningYear, and jobTitle, only null value is allowed to set)
o Two functions i.e. setCourseID() and setCourseTitle()
· Only an instance of class DeanHOD should be able to modify values for employeeID, designation of an employee, ID and name of a particular course.
Implement all these classes and within the main function, create instances of all classes (except class Employee) and test the described working of all these classes.
Comments (4)
Ask a new question
The correct answer and explanation is:
Here’s a C++ implementation based on the given problem statement, followed by an explanation of the solution.
Explanation
- Class Person:
- Encapsulates common attributes:
nameandyear_of_birth. - A constructor initializes these attributes.
- Encapsulates common attributes:
- Class Student:
- Inherits from
Personand addsstudentIDandenrolledSemester. - Constructor initializes both inherited and new attributes.
displaymethod outputs all attributes.
- Inherits from
- Class Employee:
- Contains employee-specific attributes:
employeeID,joiningYear,jobTitle,courseID, andcourseTitle.
- Contains employee-specific attributes:
- Class Administration:
- Inherits from
Employeeand ensurescourseIDandcourseTitleare set to"null". - Provides methods to set and get the job title.
- Inherits from
- Class Academic:
- Inherits from
Employeeand setsemployeeID,joiningYear, andjobTitleto"null". - Adds setters for course-specific attributes.
- Inherits from
- Class DeanHOD:
- Extends
Academicand allows modification ofemployeeID,jobTitle,courseID, andcourseTitle.
- Extends
- Main Function:
- Demonstrates object creation and functionality:
- A
Studentobject is displayed. - An
Administrationobject’s job title is modified. - A
DeanHODobject modifies anAdministrationobject’s details.
- A
- Demonstrates object creation and functionality:
This implementation emphasizes encapsulation and inheritance while adhering to the specified constraints.