Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ UML diagram The key functions work as follows: read This static member function creates an empty, derived employee object and then calls readData to

C++

UML diagram

image text in transcribed

The key functions work as follows:

read

This static member function creates an empty, derived employee object and then calls readData 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 a new, empty HourlyEmployee object on the heap, emp, say. and then calls emp->readData. HourlyEmployee::readData calls Employee::readData to read in the common employee fields from a file, and then reads in the hourly wage and hours worked. The pointer to the initialized object (or nullptr) is then returned.

readData

As explained above, this function first calls the base class implementation of readData, and then reads data form the file for its type of object (HourlyEmployee or SalariedEmployee).

write

This function works similarly to readData: it first calls Employee::write to write out the common data to the file, then writes out the specific derived class data.

printCheck

This function first calls Employee::printCheck to print the common check header, then prints the rest of the check according to the type of the object. See the sample output below to see how SalariedEmployee checks should look.

calcPay

Hourly Employees: An hourly employee's gross pay is calculated by multiplying the hours 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 Federal income tax, and 7.5% of the gross for state income tax.

Salaried Employees: A salaried employee's gross pay is just their weekly salary value. To compute the net pay for a salaried employee, deduct 20% of the gross for Federal income tax, 7.5% of the gross for state income tax, and 5.24% for benefits.

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 Driver

Your 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 of Employee pointers, and store the pointers to your objects in this vector. Add heap pointers 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 object's data to the file. Here is a sample execution of Option 1:

 
This program has two options: 
1 - Create a data file, or 
2 - Read data from a file and print paychecks. 
Please enter (1) to create a file or (2) to print checks:1 
 
Please enter a file name: employee.txt 
 
Data file created ... you can now run option 2. 
 

The contents of the file employee.txt should be:

 
1 
H. Potter 
Privet Drive 
201-9090 
40 
12 
2 
A. Dumbledore 
Hogwarts 
803-1230 
1200 
3 
R. Weasley 
The Burrow 
892-2000 
40 
10 
4 
R. Hagrid 
Hogwarts 
910-8765 
1000 

When you run option 2, your program should create a new vector of Employee pointers. Make four calls to either HourlyEmployee::read or SalariedEmployee::read, according to the same order that you wrote the objects in part 1. Add the pointers returned by read to your vector. Then loop through the vector printing out the checks. Here is an execution of Option 2:

 
This program has two options: 
1 - Create a data file, or 
2 - Read data from a file and print paychecks. 
Please enter (1) to create a file or (2) to print checks:2 
 
Please enter a file name: employee.txt 
 
--------------------FluffShuffle Electronics------------------------------- 
 
 
Pay to the order of H. Potter....................................$348.00 
 
 
United Bank of Eastern Orem 
 
 
 
Hours worked: 40.00 
HourlyWage: 12.00 
 
 
 
--------------------FluffShuffle Electronics------------------------------- 
 
 
Pay to the order of A. Dumbledore....................................$807.12 
 
 
United Bank of Eastern Orem 
 
 
 
Salary: 1200.00 
 
 
 
--------------------FluffShuffle Electronics------------------------------- 
 
 
Pay to the order of R. Weasley....................................$290.00 
 
 
United Bank of Eastern Orem 
 
 
 
Hours worked: 40.00 
HourlyWage: 10.00 
 
 
 
--------------------FluffShuffle Electronics------------------------------- 
 
 
Pay to the order of R. Hagrid....................................$672.60 
 
 
United Bank of Eastern Orem 
 
 
 
Salary: 1000.00 

From the end user's point of view, your program will work just as it did before.

abstract>> Employee empNum int name: string - address: string phone string # Employee( ) = default # readData( : ifstream) : void + Employee(numint, name:string, addr.string, phone:string + getEmpNum(): int + getName(): string + getAddress() string +getPhone): string + setName(string): void + setAddress(string): void + setPhone(string): voicd + writel: ofstream): void + calcPay(): double + printCheck(): void Hourly Employee SalariedEmployee -hoursWorked: double - hourly Wage: double # HourlyEmployee( ) = default # readData( : ifstream ) : void override + HourlyEmployee(. + getHoursWorked(): double + getHourly Wage(): double + setHoursWorked(double void + setHourly Wage(double) void + write ofstream): void override + calcPay(): double override + printCheck): void override + read( ifstream): HourlyEmployee salary double # SalariedEmployee( ) = default # readDataf; istream) : void override + SalariedEmployee(.) + getSalary(): double + setSalary(double): void + write(: ifstream): void override + calcPay): double override +printCheck() void override + read(: ifstream SalariedEmployee

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions