employee
firstName, lastName, monthlyPay
|
readEmployee
|
|
computePay
|
|
  displayEmployee
|
salesPerson
salayStaff hourlyWorker
baseSalary, amountOfSales monthlySalary workHours, hourlyRate
|
readEmployee
|
|
readEmployee
|
|
readEmployee
|
|
computePay
|
computePay
|
computePay
|
|
displayEmployee
|
displayEmployee
|
displayEmployee
|
Classes
and Inheritance:
See the conceptual depiction of a 2-level class
hierarchy of four classes in the diagram above:
- One base class
(the parent class): the employee class
(with the data members firstName, lastName, monthlyPay storing
the information of the name and the monthly pay of an employee)..
- For classes (child
classes) derived from the employee class:
- the salesPerson (with the data members baseSalary
and amountOfSales storing the information of the
monthly base salary and the monthly amount of sales for a salesperson),
- the salaryStaff (with the data members monthlySalary
storing the information of the fixed monthly salary for a staff), and
- the hourlyWorker (with the data members workHours
and hourlyRate storing the information of the
monthly work hours and the hourly rate for a part-time hourly worker).
Implementation of the Classes:
Define for each class a header file and a .cpp
file to implement the member functions in the following way:
- The readEmployee method in the base class should ask for the user inputs to fill in
the information into the firstName and lastName data members while the readEmployee method in each of the derived
classes should call the base class’s readEmployee method first for that purpose and
then ask for the inputs into their own specific data members such as baseSalary
and amountOfSales
for the salesperson class.
- Note that the computePay method in the base class, i.e. the employee class should be a pure abstract method like the readFigure, computerArea,
and computePerim
methods in the 2D
figure example since we cannot determine how to calculate the monthly pay
unless we know more specifically whether the object is a salesperson, a
salary staff person, or an hourly worker. For the salesPerson class, the monthly pay is the base
monthly salary plus 10% of the amount of the sales the person generates.
For the salaryStaff
class, the monthly pay is the fixed monthly salary. For the hourlyWorker class, the monthly pay is the work
hours multiplied by the hourly rate.
- The displayEmployee method in the base class should display the firstName and lastName
and mothlyPay
data members while the displayEmployee method
in each of the derived classes should call the base class’s displayEmployee method first for that purpose and
then display their own specific data members such as baseSalary
and amountOfSales
for the salesperson class
respectively.
Polymorphic
Data Structures:
- In your main function, declare basePtrVector as a vector of pointers to employee objects in you main
function. Like the variable myFig in the main function of the file figureTest.cpp in
the 2D figure
example, these pointers are polymorphic and can point to objects of
any of the derived classes salesPerson, salaryStaff, or hourlyWorker.
- In other words, you can dynamically allocate
objects in any of the child classes (salesPerson, salaryStaff, hourlyWorker) , cast the type of the pointers to these
objects as employee* (i.e.
the pointer type to employee objects),
and store these pointers in the vector of pointers, basePtrVector. For tdetails of
how to accomplish this, please see the related code regarding a similar
vector of base class pointers basePtrVector in the main
function of the example project,
which we examined in the class on polymorphism about.
Main function and the menu service: your main function
should provide a menu of service that allows
- the user to
dynamically add a new record of employee of any of the three categories of
employees and to
- compute and then display
the current monthly pay and other employee information for all current
employees.
See the main function of
the file figureTest.cpp
in the 2D figure
example to see how this may be done.