c++ question

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

  1. Class Person:
    • Encapsulates common attributes: name and year_of_birth.
    • A constructor initializes these attributes.
  2. Class Student:
    • Inherits from Person and adds studentID and enrolledSemester.
    • Constructor initializes both inherited and new attributes.
    • display method outputs all attributes.
  3. Class Employee:
    • Contains employee-specific attributes: employeeID, joiningYear, jobTitle, courseID, and courseTitle.
  4. Class Administration:
    • Inherits from Employee and ensures courseID and courseTitle are set to "null".
    • Provides methods to set and get the job title.
  5. Class Academic:
    • Inherits from Employee and sets employeeID, joiningYear, and jobTitle to "null".
    • Adds setters for course-specific attributes.
  6. Class DeanHOD:
    • Extends Academic and allows modification of employeeID, jobTitle, courseID, and courseTitle.
  7. Main Function:
    • Demonstrates object creation and functionality:
      • A Student object is displayed.
      • An Administration object’s job title is modified.
      • A DeanHOD object modifies an Administration object’s details.

This implementation emphasizes encapsulation and inheritance while adhering to the specified constraints.

Scroll to Top