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.
Full time
Part time

jwenting commented: lazy homework kiddo -3

Recommended Answers

All 5 Replies

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{

// default constructor
teacher() = default;

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

Does this help any? Are you able to see how to do the rest now?

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...

@ne0h: Although jwenting is probably right, the effort is much appriciated.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.