1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int hours, OvertimeHours, DoubletimeHours, dependents, WorkStatus, MoreData, EmployeeNumber, count;
double GrossPay, PayRate, BasePay, OvertimePay, DoubletimePay, IRADeduction, ModifiedGrossPay, Withholdings, NetPay, HCCost;
double calculatePay(int hours, double PayRate); //COMPUTES PAY
double IRAFunc(double GrossPay); //COMPUTES IRA DEDUCTIONS
double WithholdingsFunc(int dependents, double ModifiedGrossPay, double IRADeduction); //COMPUTES WITHHOLDINGS FROM DEPENDENTS AND WITHHOLDING PERCENTAGES
double HCCostFunc (int WorkStatus, double ModifiedGrossPay); //COMPUTES HEALTCHARE BENEFITS COST
int main()
{
ifstream in_stream;
ofstream out_stream;
in_stream.open("employeeData.dat");
if(in_stream.fail())
{
cout << "Employee data file opening failed.\n";
exit(1);
}
out_stream.open("payrollData.dat");
if(out_stream.fail())
{
cout << "Payroll Data file opening failed.\n";
exit(1);
}
in_stream >> MoreData;
count = 1;
while (MoreData != 0)
{
in_stream >> PayRate >> hours >> dependents >> WorkStatus >> MoreData;
calculatePay(hours, PayRate); //EARNINGS FUNCTION CALL
IRAFunc(GrossPay); //IRA FUNCTION CALL
WithholdingsFunc(dependents, ModifiedGrossPay, IRADeduction); //WITHOLDINGS FUNCTION CALL
HCCostFunc(WorkStatus, ModifiedGrossPay); //MEDICAL BENEFITS FUNCTION CALL
NetPay = ModifiedGrossPay - Withholdings - HCCost; //NET PAY AFTER MEDICAL BENEFITS COST
EmployeeNumber = count; //EMPLOYEE NUMBER IN ORDER OF DATA RECEIVED
count++;
//DATA OUTPUTTED TO PAYROLL DATA FILE
out_stream.setf(ios::fixed);
out_stream.setf(ios::showpoint);
out_stream.precision(2);
out_stream << "EMPLOYEE RECORD NUMBER - " << EmployeeNumber << endl;
out_stream << "Hours: " << hours << endl;
out_stream << "Hourly Rate: " << PayRate << endl;
out_stream << endl;
out_stream << "Base Pay = $" << BasePay << endl;
out_stream << "Overtime Hours: " << OvertimeHours << endl;
out_stream << "Overtime Pay at Time and a Half = $" << OvertimePay << endl;
out_stream << "Overtime Hours at Double Time: " << DoubletimeHours << endl;
out_stream << "Overtime Pay at Double Time = $" << DoubletimePay << endl;
out_stream << "Gross Pay = $" << GrossPay << endl;
out_stream << endl;
out_stream << "IRA Deductions = $" << IRADeduction << endl;
out_stream << "Modified Gross Pay = $" << ModifiedGrossPay << endl;
out_stream << "Taxes Withheld = $" << Withholdings << endl;
out_stream << "Medical Benefits Deduction = $" << HCCost << endl;
out_stream << endl;
out_stream << "Net Pay = $" << NetPay << "\n\n\n\n\n";
}
in_stream.close();
out_stream.close();
return 0;
}
//THIS FUNCTION CALCULATES GROSSPAY
double calculatePay(int hours, double PayRate)
{
BasePay = PayRate * 40;
//IF DOUBLETIME AND OVERTIME IS WORKED
if (hours > 50)
{
DoubletimeHours = hours - 50;
DoubletimePay = 2 * PayRate * DoubletimeHours;
OvertimeHours = 10;
OvertimePay = 1.5 * PayRate * OvertimeHours;
GrossPay = BasePay + OvertimePay + DoubletimePay;
}
//IF ONLY OVERTIME IS WORKED
else if (hours > 40)
{
DoubletimeHours = 0;
DoubletimePay = 0;
OvertimeHours = hours - 40;
OvertimePay = 1.5 * PayRate * OvertimeHours;
GrossPay = BasePay + OvertimePay;
}
//NO OVERTIME
else
{
BasePay = PayRate * hours;
GrossPay = BasePay;
DoubletimeHours = 0;
DoubletimePay = 0;
OvertimeHours = 0;
OvertimePay = 0;
}
return (DoubletimeHours, DoubletimePay, OvertimeHours, OvertimePay, GrossPay);
}
//THIS FUNCTION CALCULATES IRA DEDUCTIONS
double IRAFunc(double GrossPay)
{
if (GrossPay < 400)
IRADeduction = 0;
else if (GrossPay >= 400 && GrossPay < 500)
IRADeduction = GrossPay * 0.05;
else if (GrossPay >= 500)
IRADeduction = GrossPay * 0.10;
ModifiedGrossPay = GrossPay - IRADeduction;
return (IRADeduction, ModifiedGrossPay);
}
//THIS FUNCTION CALCULATES WITHHOLDINGS
double WithholdingsFunc(int dependents, double ModifiedGrossPay, double IRADeduction)
{
double Percentage;
if (dependents == 0)
Percentage = 0.28;
else if (dependents == 1)
Percentage = 0.20;
else if (dependents == 2)
Percentage = 0.18;
else
Percentage = 0.15;
Withholdings = Percentage * ModifiedGrossPay;
return (Withholdings, ModifiedGrossPay);
}
//THIS FUNCTION CALCULATES MEDICAL BENEFITS COST
double HCCostFunc (int WorkStatus, double ModifiedGrossPay)
{
float Percentage;
if (WorkStatus == 1)
Percentage = 0.07;
else if (WorkStatus == 0)
Percentage = 0;
HCCost = ModifiedGrossPay * Percentage;
return (HCCost, ModifiedGrossPay);
}
| |