please use C++ here are 4 deductions //contants for deduction percentages const
ID: 3714661 • Letter: P
Question
please use C++
here are 4 deductions
//contants for deduction percentages
const double FEDERAL_WITHOLDING_RATE = 0.18;
const double STATE_WITHOLDING_RATE = 0.045;
const double HOSPITALIZATION = 25.65;
const double UNION_DUES = 0.02;
Assignment Plan and code a program utilizing at least three functions to solve the following problem to calculate payroll information for Natural Oak and Pine Furniture Company. Now that we have the ability to handle errors, can process data that falls into different categories, and the ability to process more than one set of data during one program run, let's incorporate this into a new program for Natural Oak and Pine Furniture Company Develop a top-down design and write a program to determine payroll information for all employees at Natural Oak and Pine Furniture Company. (This will expand the program created for Lab 2A) All data will be input from a file Payln.Txt (See below).Develop a subprogram for each-task involved in this problem. Use value and reference parameters for passing all data between modules, Determine the total hours worked by each employee during the week. Calculate each employees total pay based on the following scale of hours worked 0 through 40 hours more than 40 through 60 hours more than 60 through 80 hours regular pay 1 1/2 pay double pay Determine deductions (state withholding, federal withholding, union dues, and hospitalization) for each employee (as calculated in Lab 2A). Determine the gross pay (before deductions) and net pay (after deductions) Output to a new file--PayOut.Txt: 3 employee initials, total hours worked, pay rate, the amount of each deduction (federal withholding, state withholding, union dues, and hospitalization), gross pay, and net pay Input 3 employee initials, 7 numbers (representing the hours worked during 7 days), and the employee's hourly rate of pay Error check data input from the file (by the input module). Create the data file below using your text editor or Notepad Data File ABC 8.0 8.0 8.0 8.0 8.0 0.00.0 8.75 DEF 10.0 10.0 10.0 10.0 10.0 0.0 0.0 9.75 GHI 8.010.0 6.0 10.0 9.0 10.0 12.0 10.00 JKL 0.0 0.0 5.0 6.07.08.06.08.75 MNO 8.0 POR 10.0 10.0 8.0 10.0 6.0 3.0 2.0 9.75 STU 9.011.5 5.5 7.5 9.5 2.5 0.011.50 VWX 25.0 0.0 0.0 8.57.55.5 0.0 12.50 XYZ 10.0 10.0 10.0 10.0 10.0 0.0 0.05.00 AAA 0.0 0.00.025.0 1.0 0.0 0.0 15.75 8.0 8.0 8.0 8.0 8.0 80.0 8.00 Output To an output file: 3 initials, total hours worked, hourly rate of pay, amount of each of 4 deductions (federal withholding, state withholding, union dues, hospitalization), gross pay, net pay. Output valid data to PayOut.Txt Output errors to an error file Turn in Top down design with parameters, program listing and program output Turn in all data files used in the program. Program documentation and first lines in the output file should include: //Last Name, First Name //Class Section Number, Day, Time //Lab Number and Assignment Due DateExplanation / Answer
#include<iostream>
#include <fstream> // For ifstream
#include <stdlib.h> // For function exit()
#include<string>
#define MAX 100
using namespace std;
// Constants for deduction percentages
const double FEDERAL_WITHOLDING_RATE = 0.18;
const double STATE_WITHOLDING_RATE = 0.045;
const double HOSPITALIZATION = 25.65;
const double UNION_DUES = 0.02;
// Class Employee definition
class Employee
{
// Data member to store employee information
string name;
double hoursWorked[7];
double totalHours;
double hourlyPay;
double federalTax;
double stateTax;
double hospital;
double unionDue;
double grossPay;
double netPay;
public:
// Prototype of member functions
Employee();
int readFile(Employee[]);
void calculatePay(Employee[], int);
void displayPay(Employee[], int);
};// End of class
// Default constructor to initialize data members
Employee::Employee()
{
name = "";
// Loops 7 times for hours worked in a week
for(int x = 0; x < 7; x++)
hoursWorked[x] = 0;
hourlyPay = federalTax = stateTax = hospital = unionDue = grossPay = netPay = 0;
}// End of default constructor
// Function to read employee data from file and stores it in array of object employee
int Employee::readFile(Employee employee[])
{
// File stream object declared
ifstream fileRead;
// For number of scores
int counter = 0;
// Open the file for reading
fileRead.open("Payin.txt");
// Check that file can be opened or not
// is_open() function returns true if a file is open and associated with this stream object.
// Otherwise returns false.
if(!fileRead.is_open())
{
// Displays error message
cout<<" Error: Unable to open the file! Please re - enter the file name.";
}// End of if condition
// Loops till not end of the file
// eof() function returns true if the stream's eofbit error state flag is set (which signals that the End-of-File has been reached
// by the last input operation). Otherwise returns false.
while(!fileRead.eof())
{
// Reads employee name
fileRead>>employee[counter].name;
// Loops 7 times to read hours worked in a week
for(int x = 0; x < 7; x++)
fileRead>>employee[counter].hoursWorked[x];
// Reads pay rate
fileRead>>employee[counter].hourlyPay;
// Increase the record counter by one
counter++;
}// End of while condition
// Close the file
fileRead.close();
// Returns the record counter
return counter;
}// End of function
// Function to display employee information
void Employee::displayPay(Employee emp[], int len)
{
// Loops till number of records
for(int x = 0; x < len; x++)
{
// Displays employee number
cout<<" Employee "<<(x + 1)<<" information. ";
cout<<" Name: "<<emp[x].name;
cout<<" Hours worked: ";
// loops 7 times to display each employee each day hours worked
for(int y = 0; y < 7; y++)
cout<<emp[x].hoursWorked[y]<<" ";
cout<<" Total hours worked: "<<emp[x].totalHours;
cout<<" Hourly pay: "<<emp[x].hourlyPay;
cout<<" Gross Pay: "<<emp[x].grossPay;
cout<<" Deductions ";
cout<<" Federal Tax: "<<emp[x].federalTax;
cout<<" State Tax: "<<emp[x].stateTax;
cout<<" Hospitalization: "<<emp[x].hospital;
cout<<" Union Due: "<<emp[x].unionDue;
cout<<" Take home pay: "<<emp[x].netPay;
}// End of for loop
}// End of function
// Function to calculate each employee payment
void Employee::calculatePay(Employee emp[], int len)
{
// Loops till number of records
for(int x = 0; x < len; x++)
{
// Initializes each employee total hours
emp[x].totalHours = 0;
// Loops 7 time to calculate the total hours worked for each employee
for(int y = 0; y < 7; y++)
emp[x].totalHours += emp[x].hoursWorked[y];
// Checks if the current employee total hours worked is less than or equals to 40
if(emp[x].totalHours <= 40)
// Calculate regular pay
emp[x].grossPay = emp[x].totalHours * emp[x].hourlyPay;
// Otherwise checks if the current employee total hours worked is less than or equals to 60
else if(emp[x].totalHours <= 60)
// Calculates regular pay 1.5 times
emp[x].grossPay = (emp[x].totalHours * emp[x].hourlyPay) * 1.5;
// Otherwise current employee total hours worked is more than 60
else
// Calculates regular pay double
emp[x].grossPay = (emp[x].totalHours * emp[x].hourlyPay) * 2.0;
// Calculates each employee federal tax
emp[x].federalTax = emp[x].grossPay * FEDERAL_WITHOLDING_RATE;
// Calculates each employee state tax
emp[x].stateTax = emp[x].grossPay * STATE_WITHOLDING_RATE;
// Calculates each employee hospital tax
emp[x].hospital = emp[x].grossPay * HOSPITALIZATION;
// Calculates each employee union tax
emp[x].unionDue = emp[x].grossPay * UNION_DUES;
// Calculates each employee net pay
emp[x].netPay = emp[x].grossPay - (emp[x].federalTax + emp[x].stateTax + emp[x].hospital + emp[x].unionDue);
}// End of for loop
}// End of function
// main function definition
int main()
{
// Creates an array of object of size MAX
Employee employee[MAX];
// Calls the function to read file and stores the data in array of objects
// Returns number of record stored in len
int len = employee[0].readFile(employee);
// Calls the function to calculate payment of each employee
employee[0].calculatePay(employee, len);
// Calls the function to display information of each employee
employee[0].displayPay(employee, len);
}// End of main function
Sample Output:
Employee 1 information.
Name: ABC
Hours worked: 8 8 8 8 8 0 0
Total hours worked: 40
Hourly pay: 8.75
Gross Pay: 350
Deductions
Federal Tax: 63
State Tax: 15.75
Hospitalization: 8977.5
Union Due: 7
Take home pay: -8713.25
Employee 2 information.
Name: DEF
Hours worked: 10 10 10 10 10 0 0
Total hours worked: 50
Hourly pay: 9.75
Gross Pay: 731.25
Deductions
Federal Tax: 131.625
State Tax: 32.9062
Hospitalization: 18756.6
Union Due: 14.625
Take home pay: -18204.5
Employee 3 information.
Name: GHI
Hours worked: 8 10 6 10 9 10 12
Total hours worked: 65
Hourly pay: 10
Gross Pay: 1300
Deductions
Federal Tax: 234
State Tax: 58.5
Hospitalization: 33345
Union Due: 26
Take home pay: -32363.5
Employee 4 information.
Name: JKL
Hours worked: 0 0 5 6 7 8 6
Total hours worked: 32
Hourly pay: 8.75
Gross Pay: 280
Deductions
Federal Tax: 50.4
State Tax: 12.6
Hospitalization: 7182
Union Due: 5.6
Take home pay: -6970.6
Employee 5 information.
Name: MNO
Hours worked: 8 8 8 8 8 8 80
Total hours worked: 128
Hourly pay: 8
Gross Pay: 2048
Deductions
Federal Tax: 368.64
State Tax: 92.16
Hospitalization: 52531.2
Union Due: 40.96
Take home pay: -50985
Employee 6 information.
Name: PQR
Hours worked: 10 10 8 10 6 3 2
Total hours worked: 49
Hourly pay: 9.75
Gross Pay: 716.625
Deductions
Federal Tax: 128.993
State Tax: 32.2481
Hospitalization: 18381.4
Union Due: 14.3325
Take home pay: -17840.4
Employee 7 information.
Name: STU
Hours worked: 9 11.5 5.5 7.5 9.5 -2.5 0
Total hours worked: 40.5
Hourly pay: 11.5
Gross Pay: 698.625
Deductions
Federal Tax: 125.752
State Tax: 31.4381
Hospitalization: 17919.7
Union Due: 13.9725
Take home pay: -17392.3
Employee 8 information.
Name: VWX
Hours worked: 25 0 0 8.5 7.5 5.5 0
Total hours worked: 46.5
Hourly pay: 12.5
Gross Pay: 871.875
Deductions
Federal Tax: 156.938
State Tax: 39.2344
Hospitalization: 22363.6
Union Due: 17.4375
Take home pay: -21705.3
Employee 9 information.
Name: XYZ
Hours worked: 10 10 10 10 10 0 0
Total hours worked: 50
Hourly pay: -5
Gross Pay: -375
Deductions
Federal Tax: -67.5
State Tax: -16.875
Hospitalization: -9618.75
Union Due: -7.5
Take home pay: 9335.62
Employee 10 information.
Name: AAA
Hours worked: 0 0 0 25 1 0 0
Total hours worked: 26
Hourly pay: 15.75
Gross Pay: 409.5
Deductions
Federal Tax: 73.71
State Tax: 18.4275
Hospitalization: 10503.7
Union Due: 8.19
Take home pay: -10194.5
Payin.txt file contents
ABC 8.0 8.0 8.0 8.0 8.0 0.0 0.0 8.75
DEF 10.0 10.0 10.0 10.0 10.0 0.0 0.0 9.75
GHI 8.0 10.0 6.0 10.0 9.0 10.0 12.0 10.00
JKL 0.0 0.0 5.0 6.0 7.0 8.0 6.0 8.75
MNO 8.0 8.0 8.0 8.0 8.0 8.0 80.0 8.00
PQR 10.0 10.0 8.0 10.0 6.0 3.0 2.0 9.75
STU 9.0 11.5 5.5 7.5 9.5 -2.5 0.0 11.50
VWX 25.0 0.0 0.0 8.5 7.5 5.5 0.0 12.50
XYZ 10.0 10.0 10.0 10.0 10.0 0.0 0.0 -5.00
AAA 0.0 0.0 0.0 25.0 1.0 0.0 0.0 15.75
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.