Consider the following class hierarchy of preschool teachers of ABC school, to answer the
questions from i to iv.
*Preschool teachers
full time teachers
part time teachers

All Preschool teachers have a teacher ID, name, age and Highest qualification. A full time
teacher has a fixed monthly salary. He/She has to necessarily contribute to the
EPF(Employee Provident Fund) and a monthly fee for the sports club, which is deducted
from his/her monthly salary. A part time teacher does not contribute to the EPF or to the
Sports club and He/She is paid a daily salary.
Piyal is a Full time teacher and Amara is a Part time teacher assigned to the school.
i. Identify appropriate data members for the base and derived classes according to
the description given above.
ii. Declare the base class using C++ coding.
iii. Implementing a function named print_details() in both the derived classes,
declare the derived classes using C++ coding. The function must be
implemented so that it demonstrates polymorphism.
iv. Write C++ coding for the following on the main function
a. Assuming values for the data members, create an instance (Piyal)
of the class Full time teacher and assign values to it.
b. Assuming values for the data members, create an instance (Amara)
of the class Part time teacher and assign values to it.
c. Display the details of Piyal and Amara by calling the function
print_details() as appropriate.
-ENDPreschool
Teacher
Full time
teacher
Part time
teacher

Comments
lazy homework kiddo

Ok to start you off, the first question is easy enough. i.e identify appropriate data members for the base and derived classes.

I would say that all teachers have an ID, age and highest qualification irrespective of whether they are full time or part time. For this reason, the attributes of a pre-school teacher should be inherited by full-time and part-time teachers. Pre-school should be the base class here. Full-time and Part-time should be derived classes.

The data members of each might include:

string teacher_id;
int age;
string qualification;
double monthly_salary;
double epf;
double sports_fee;
double daily_salary;

Hopefully this should get you started.

ii) So to declare the base class would be

class teacher{
public:

// default constructor
teacher() = default;

// data members
std::string teacher_id;
int age;
std::string qualification;
};

Edited 2 Years Ago by ne0h

seeing as all his "questions" have just been verbatim dumps of homework assignments, I seriously doubt he's capable of seeing how to do anything himself...

This article has been dead for over six months. Start a new discussion instead.