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
|
#include <iostream>
# include <fstream>
# include <iomanip>
#include <string>
using namespace std;
void GetData(string &, double &, double &, double &, double &, double &, double &, double &, double &, double &, bool &, bool &, ifstream & Infile, ofstream & Errorfile);
void calcPay(double, double, double &, double &, double &, double &, double &, double &);
void Output(string, double, double, double, double, double, double, double, double, ofstream & Outfile);
int main()
{
ifstream Infile;
ofstream Outfile, Errorfile;
string employee;
double mon, tues, wed, thurs, fri, sat, sun, ratepay, total, grosspay, netpay, fedwithold, statewithold, unionDue, hospital;
;
bool workhourError, rateError;
Infile.open("E:\\PayIn.txt");
if (!Infile.is_open()) {
cout << "Could not PayIn file." << endl;
exit(1);
}
Errorfile.open("E:\\Errorfile.txt");
if (!Errorfile.is_open()) {
cout << "Error file could not be open" << endl;
exit(1);
}
while (!Infile.eof())
{
GetData(employee, mon, tues, wed, thurs, fri, sat, sun, ratepay, total, workhourError, rateError, Infile, Errorfile);
if (workhourError && rateError)
{
calcPay(total, ratepay, netpay, grosspay, fedwithold, statewithold, unionDue, hospital);
Output(employee, total, ratepay, netpay, grosspay, fedwithold, statewithold, unionDue, hospital, Outfile);
}
}
Infile.close();
Outfile.close();
return 0;
}
void GetData(string & employee, double & mon, double & tues, double & wed, double & thurs, double & fri, double & sat, double & sun, double & ratepay, double & total, bool & workhourError, bool & rateError, ifstream & Infile, ofstream & Errorfile)
{
Infile >> employee >> mon >> tues >> wed >> thurs >> fri >> sat >> sun >> ratepay;
if (mon && tues && wed && thurs && fri && sat && sun < 0)
{
workhourError = false;
}
else
workhourError = true;
if (ratepay < 0)
{
rateError = false;
}
else
rateError = true;
if (!rateError || !workhourError)
{
Errorfile << fixed << showpoint << setprecision(2);
Errorfile << "Error in following data:" << employee << " " << mon << " " << tues << " " << wed << " " << thurs << " " << fri << " " << sat << " " << sun << ratepay << endl;
}
total = mon + tues + wed + thurs + fri + sat + sun;
}
void calcPay(double total, double ratepay, double & netpay, double & grosspay, double & fedwithold, double & statewithold, double & unionDue, double & hospital)
{
cout << fixed << showpoint << setprecision(2);
if (total > 40 && total <= 60)
{
ratepay = (ratepay * 1.50);
}
else if (total > 60 && total <= 80)
{
ratepay = (ratepay *2.0);
}
grosspay = ratepay * total;
fedwithold = grosspay * 0.18;
statewithold = grosspay * 0.045;
hospital = 25.65;
unionDue = grosspay * .02;
netpay = grosspay - fedwithold - statewithold - hospital - unionDue;
}
void Output(string employee, double total, double ratepay, double netpay, double grosspay, double fedwithold, double statewithold, double unionDue, double hospital, ofstream & Outfile)
{
Outfile.open("E:\\PayOut.txt");
if (!Outfile.is_open()) {
cout << "PayOut file could not be open" << endl;
exit(1);
}
Outfile << fixed << showpoint << setprecision(2);
Outfile << "Employee:\t\t" << employee << "\nHourly Rate:\t\t " << ratepay << "\nHours Worked:\t\t " << total << "\nGross Pay:\t\t" << grosspay << "\n Federal Withholding: \t " << fedwithold << "\nState Withholding: \t " << statewithold << "\nUnion Dues: \t\t " << unionDue <<
"\nHospitalization:\t" << hospital << "\nNet Pay:\t\t" << netpay << endl;
}
|