12.8 Programming Project #7:An Employee Class HierarchyBackgroundThe code that you wrote for the second Employee project only works for hourlyemployees. Now that we have studied polymorphism, we can begin to make ourpayroll program more general. The most important thing we will do is enablepolymorphism in our Employee class hierarchy, so that employee objects of differenttypes automatically behave correctly.Objectives Continue gaining experience with object-oriented design Learn to create a class hierarchy that is enabled for polymorphism Learn to use polymorphism in a program.The ProgramWe will rename Employee to HourlyEmployee, and then create two new classes,Employee and SalariedEmployee, as depicted in the class diagram below.


(Items preceded by dashes are private, those preceded by a # are protected, andpublic members start with a +. Static members appear underlined.)Employee is an abstract class, meaning that it exists to hold what is common to all itsderived classes, and is not to be instantiated directly by users. For this reason, it hasno public constructors.In addition to defining all things common to the derived employee classes, Employeedefines a virtual destructor and declares four pure virtual functions, which areoverridden in the derived classes (see the italicized functions in Employee above). Allof these functions have bodies in Employee except calcPay, and are called explicitlyfrom their derived counterparts. Note that readData functions as well as defaultconstructors have protected access. This is because we dont want users to createinstances of the concrete, derived employee objects directly without completeinformation.Also, remember that base classes must always have a virtual destructor, even if thebody of that destructor is empty (which is what = default accomplishes here).Finally, the parameterized constructors for the derived classes take all pertinentparameters for objects of their type (which includes data common to all employees).The key functions work as follows:readThis static member function creates an empty, derived employee object and then callsreadData to initialize it. It returns a pointer to a new object, if data was read correctly,or nullptr if there was an input error. For example, HourlyEmployee::read creates anew, empty HourlyEmployee object on the heap, emp, say. and then calls emp->readData. HourlyEmployee::readData calls Employee::readData to read in thecommon employee fields from a file, and then reads in the hourly wage and hoursworked. The pointer to the initialized object (or nullptr) is then returned.readDataAs explained above, this function first calls the base class implementationof readData, and then reads data from the file for its type of object (HourlyEmployeeor SalariedEmployee).writeThis function works similarly to readData: it first calls Employee::write to write outthe common data to the file, then writes out the specific derived class data.printCheckThis function first calls Employee::printCheck to print the common check header, thenprints the rest of the check according to the type of the object. See the sample outputbelow to see how SalariedEmployee checks should look.calcPayHourly Employees: An hourly employees gross pay is calculated by multiplying thehours worked by their hourly wage. Be sure to give time-and-a-half for overtime(anything over 40 hours). To compute the net pay, deduct 20% of the gross for Federalincome tax, and 7.5% of the gross for state income tax.Salaried Employees: A salaried employees gross pay is just their weekly salary value.To compute the net pay for a salaried employee, deduct 20% of the gross for Federalincome tax, 7.5% of the gross for state income tax, and 5.24% for benefits.The main() FunctionYour driver will provide the same set of options as in the previous project. However,your driver code should be somewhat simpler because you will now create a vector ofEmployee pointers, and store the pointers to your objects in this vector. Add heappointers to the following employees to your vector:HourlyEmployee(1, H. Potter, Privet Drive, 201-9090, 40,12.00);SalariedEmployee(2, A. Dumbledore, Hogwarts, 803-1230,1200);HourlyEmployee(3, R. Weasley, The Burrow, 892-2000, 40,10.00);SalariedEmployee(4, R. Hagrid, Hogwarts, 910-8765, 1000);You can then use a simple for-loop to save each objects data to the file.Here is a sample execution of Option 1:This program has two options:1 Create a data file, or2 Read data from a file and print paychecks.Please enter (1) to create a file or (2) to print checks:1Please enter a file name: employee.txtData file created you can now run option 2.The contents of the file employee.txt should be:1H. PotterPrivet Drive201-909040122A. DumbledoreHogwarts803-123012003R. WeasleyThe Burrow892-200040104R. HagridHogwarts910-87651000When you run option 2, your program should create a new vector of Employeepointers. Make four calls toeither HourlyEmployee::read or SalariedEmployee::read, according to thesame order that you wrote the objects in part 1. Add the pointers returned by read toyour vector. Then loop through the vector printing out the checks. Here is an executionof Option 2:This program has two options:1 Create a data file, or2 Read data from a file and print paychecks.Please enter (1) to create a file or (2) to print checks:2Please enter a file name: employee.dat..UVU Computer ScienceDeptPay to the order of H.Potter$348.00United Community Credit Union…Hours worked: 40.00HourlyWage: 12.00..UVU Computer ScienceDeptPay to the order of A.Dumbledore$807.12United Community Credit Union…Salary: 1200.00..UVU Computer ScienceDeptPay to the order of R.Weasley$290.00United Community Credit Union…Hours worked: 40.00HourlyWage: 10.00..UVU Computer ScienceDeptPay to the order of R.Hagrid$672.60United Community Credit Union…Salary: 1000.00From the end users point of view, your program will work just as it did before.

![[Solved] CS-1410-Project 7-An Employee Class Hierarchy](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip.jpg)

![[Solved] CS-1410-Project 1 Taxes](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip-1200x1200.jpg)
Reviews
There are no reviews yet.