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
|
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
ifstream infile;
ofstream outfile, errorfile;
void GetData (string& firstname, string& lastname, double& wage, double& hours, int& exemptions, char& maritalstatus);
double Gross (double wage, double hours);
double FITW (double Gross, int exemptions, char maritalstatus);
double FICA (double Gross);
void SendData (string firstname, string lastname, double hours, double wage, double Gross, double FICA, double FITW, double netpay);
int main ()
{
infile.open("employee.txt");
string firstname, lastname;
double wage, hours, fitw, grosspay, ficatax, netpay;
char maritalstatus;
int exemptions;
GetData (firstname, lastname, wage, hours, exemptions, maritalstatus);
infile.close();
grosspay = Gross (hours, wage);
ficatax = FICA (grosspay);
fitw = FITW (grosspay, exemptions, maritalstatus);
netpay = grosspay - ficatax - fitw;
SendData (firstname, lastname, hours, wage, grosspay, ficatax, fitw, netpay);
}
void GetData (string& firstname, string& lastname, double& wage, double& hours, int& exemptions, char& maritalstatus)
{
infile >> firstname >> lastname >> wage >> hours >> exemptions >> maritalstatus;
}
double Gross(double wage, double hours)
{
return (wage*hours);
}
double FITW (double Gross, int exemptions, char maritalstatus)
{
double AWIncome;
AWIncome=Gross-(exemptions*73.08);
if ((AWIncome<=721) && (maritalstatus=='S' || 's'))
return (0);
else if ((AWIncome>721 && AWIncome<=7510) && (maritalstatus=='S' || 's'))
return ((AWIncome-721)*0.28+93.60);
else
return ((AWIncome-7510)*0.35+2167.16);
if ((AWIncome<=1515) && (maritalstatus=='M' || 'm'))
return (0);
else if ((AWIncome>1515 && AWIncome<=7624) && (maritalstatus=='M' || 'm'))
return ((AWIncome-1515)*0.15+187.15);
else
return ((AWIncome-7624)*0.30+2020.42);
}
double FICA (double Gross)
{
const double FICAtax=0.0565;
return (Gross*FICAtax);
}
void SendData (string firstname, string lastname, double hours, double wage, double Gross, double FICA, double FITW, double netpay)
{
outfile.open("payroll.txt");
outfile <<fixed<< showpoint << setprecision(2);
outfile << "***********************************************" <<endl;
outfile <<"Payroll for: " << firstname << " " << lastname << endl;
outfile <<"Hours worked: " << hours << endl;
outfile <<"Hourly wage: " << wage << endl;
outfile <<"Gross pay: " << Gross << endl;
outfile <<"FICA tax: " << FICA << endl;
outfile <<"Federal Income Tax Witheld: " << FITW << endl;
outfile <<"Your net income is: " << netpay << endl;
outfile <<"***********************************************" <<endl;
outfile.close();
return;
}
|