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
|
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
ifstream infile;
ofstream outfile, errorFile;
void retrieveData(string&, double&, double&, int&, char&);
void dataCalculations(double, double, int, char, double&, double&, double&, double&, double&);
void sendData(string, int&, double, double, double, double, double, double);
int main()
{
bool clear;
ifstream infile;
ofstream outfile, errorFile;
double wage, hours, grossPay, ficaTax, incomeTax, netPay, taxWithheld;
string Name;
char Status;
int exemptions, ID;
infile.open(""); //Remember to write file name
if (!infile)
{
cout << "Error file not found." << endl;
system("pause");
exit(1);
}
else
cout << "Success!" << endl;
outfile.open(""); //Remember to write file name
errorFile.open(""); //Remember to write file name
while (infile)
{
infile >> Name >> wage >> hours >> exemptions >> Status;
retrieveData(Name, wage, hours, exemptions, Status); // Here are the errors
dataCalculations( wage, hours, exemptions, Status, grossPay, ficaTax, incomeTax, netPay, taxWithheld); //Here are the errors
sendData(Name, ID, hours, wage, ficaTax, incomeTax, grossPay, netPay); //Here are the errors
}
infile.close();
outfile.close();
errorFile.close();
system("pause");
return 0;
}
//Check for valid data
void retrieveData(string N, double w, double h, int e, char S)
{
if (w < 0 || h < 0 || S != 'M' || S != 'm' || S != 'S' || S != 's')
{
errorFile << "This employees data contains errors." << endl;
errorFile << "Name: " << N << "\tHourly Wage: " << w << "\tHours Worked: " << h << "\tExemptions: " << e << "\tMarital Status: " << S;
cout << "Error with employee data: " << N << endl;
}
}
//Calculate data
void dataCalculations(double w, double h, int e, char S, double gP, double fT, double iT, double nP, double tW)
{
bool overtime;
double remainder;
if (h < 40)
overtime = true;
else
overtime = false;
if (overtime = true)
{
remainder = h - 40;
gP = (w * 40) + (remainder*1.5*w);
}
else if (overtime = false)
{
gP = w*h;
}
fT = gP*0.0565;
iT = 73.08*e;
if (S == 'M' || S == 'm')
{
if (iT >= 0 && iT <= 1515)
tW = 0;
else if (iT >= 1515 && iT <= 7624)
tW = 187.15 + (iT*0.15 / 1515);
else if (iT >= 7624)
tW = 2020.42 + (iT*0.30 / 7624);
}
else if (S == 'S' || S == 's')
{
if (iT >= 0 && iT <= 721)
tW = 0;
else if (iT >= 721 && iT <= 7510)
tW = 93.60 + (iT*0.28 / 721);
else if (iT >= 7510)
tW = 2767.16 + (iT*0.35 / 7510);
}
nP = gP - fT - iT - tW;
}
//Send data to file
void sendData(string N, int I, double h, double w, double fT, double iT, double gP, double nP)
{
outfile << "Employee Name:" << N << endl;
outfile << "Hours Worked:" << h << endl;
outfile << "Hourly Wage:" << w << endl;
outfile << "Fica Tax Deduction:" << fT << endl;
outfile << "Income Tax Deduction:" << iT << endl;
outfile << "Gross Pay:" << gP << endl;
outfile << "Net Pay:" << nP << endl;
outfile << endl;
}
|