In this programming assignment, you will write a program that will read in an employee file that contain information about each employee, read in a file that contains information about payroll for each employee, process the payroll for each employee and write out a text file for the employee payroll report. You do need to write a UML class diagram for this program.

Employees.dat file

The employees.dat file is a binary file that contains information for the type of employee, id, first name, last name, and salary. If the employee type is hourly then salary will be the hourly wage. If the employee type is salary then salary is the weekly salary for the employee. You can use the following structure for an employee record:

const int EMPID_LENGTH = 7; // length of id is 6
const int FIRSTNAME_LENGTH = 12; // length of first name is less than 21
const int LASTNAME_LENGTH = 12; // length of last name is less than 21
struct EmployeeRecord
{
char employeeType; // H for hourly employee, S for salary employee
char id[EMPID_LENGTH]; // Id of employee
char firstName[FIRSTNAME_LENGTH]; // Employee's first name
char lastName[LASTNAME_LENGTH]; // Employee's last name
double salary; // Employee's weekly or hourly salary depending on
// type of employee
};

Emp_time.dat file

The emp_time.dat file is a binary file that contains information for employee payroll. Each record contains the employee id and hours worked for the week. You can use the following structure for an employee_time record:

struct EmployeeTime
{
char id[EMPID_LENGTH]; // ID of employee
double hours; // Hours worked for week
};

Classes

You will need to write three classes: Employee, HourlyEmployee, and SalaryEmployee

Employee

The Employee class is an abstract class and is intended to be the parent class for HourlyEmployee and SalaryEmployee. It should have three fields: id, first name, and last name. It should have one constructor that takes three parameters for id, first name and last name. It should have three getters to get the id, first name and last name. It should not have any setters. You need to overload the == (equals) operator using the id as the field to compare employees. You should have a function called calculatePay that takes a double for hours worked and returns a double for weekly wage. This function should be a pure virtual function.

HourlyEmployee

The HourlyEmployee class should publicly inherit from the Employee class. It should have one field: hourly wage. It should have one constructor that takes four parameters: id, first name, last name, and hourly wage. The HourlyEmployee constructor should call the Employee constructor with the proper parameters. It should override the calculatePay function from the Employee class. All this function needs to do is multiply the number of hours passed in by the hourly wage and return that value.

SalaryEmployee

The SalaryEmployee class should publicly inherit from the Employee class. It should have one field: weekly salary. It should have one constructor that takes four parameters: id, first name, last name, and weekly salary. The SalaryEmployee constructor should call the Employee constructor with the proper parameters. It should override the calculatePay function from the Employee class. All this funtion needs to do is return the weekly salary. Note: you will still need to pass in the hours worked, but these will be ignored since they are not used in calculating the wage for a salaried employee.

main

You have been provided with a main.cpp. The main() function is complete and has the overall logic of the program already coded. You will need to write the function definitions. You may choose not to use the provided main.cpp at all and write your own. This okay as long as you end up with the same output.

The general logic is as follows: see image.

Payroll.txt

Payroll.txt is the output file that you will create. The report should include 5 pieces of information for each employee: id, last name, first name, hours worked, and weekly pay. Each employee should be output on a single row. The employees should be sorted by employee id. Hours and weekly pay should be displayed with two decimal places.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.