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
|
// ------- Header Files -------
#include <iostream>
#include <string>
#include <cmath>
#include <fstream>
#include <iomanip>
using namespace std;
// ------- Global Variables -------
ofstream paystub;
string lName, fName, jTitle;
int dClaim, hrWorked, ID, otHours,worked;
double hrWage, pay, payaftertnd, payafterOT,wage;
char endProg;
double tax = 1.4;
double deduc = .05;
double otPay = 1.25; //one and a quarter Overtime pay
bool dontEnd = true;
//
// ------- Define Functions -------
void gatherinfo(string fName, string lName, string jTitle);
void payamount(double otPay, double hrWage, int hrWorked, double payafterOT, int otHours);
void openStub(ofstream& paystub);
void filecheck(ofstream& paystub);
void closeSeq(char endProg);
// ------- Begin Functions -------
void openStub (ofstream& paystub)
{
dontEnd = true;
paystub.open("weekpay.txt");
}
// -------------------------------------------------------------------
void filecheck(ofstream& paystub)
{
if (!paystub.is_open())
{
cout << "ERROR! File not Found." << endl;
system("pause");
exit(1);
}
}
// -------------------------------------------------------------------
void gatherinfo(string fName[1], string lName, string jTitle)
{
dontEnd = true;
system("CLS");
cout << "Please enter your first name: ";
cin >> fName[1];
cout << "Please enter your last name: ";
cin >> lName;
cout << "Please enter your job title: ";
cin.ignore();
getline (cin, jTitle);
paystub << "Employee Name: " << fName << " " << lName << endl;
paystub << "Employee Job Title: " <<jTitle<< endl;
}
// -------------------------------------------------------------------
void payamount(int dClaim, int hrWorked, int ID, double hrWage, double otPay, double payafterOT, int otHours, double tax, double payaftertnd, double deduc)
{
dontEnd = true;
system("CLS");
cout << "Please enter your employee ID#: ";
cin >> ID;
cout << "Please enter the amount of hours you worked this week:";
cin >> hrWorked;
cout << "How many deductions do you have?: ";
cin >> dClaim;
paystub << "Employee ID#:" << ID << endl;
paystub << "Employee claimed " << dClaim << " deductions." << endl;
cout << "Please enter your hourly wage: ";
cin >> hrWage;
if (hrWorked > 40)
{otHours = (hrWorked - 40);
payafterOT = ((otHours * otPay) + (40 * hrWage));}
else if (hrWorked <= 40)
{payafterOT = hrWorked * hrWage;}
if (dClaim == 0)
{payaftertnd = (payafterOT - (tax * payafterOT));}
else if (dClaim == 1)
{payaftertnd = payafterOT - (.35 * payafterOT);}
else if (dClaim == 2)
{payaftertnd = payafterOT - (.3 * payafterOT);}
else if (dClaim == 3)
{payaftertnd = payafterOT - (.25 * payafterOT);}
else if (dClaim == 4)
{payaftertnd = payafterOT - (.20 * payafterOT);}
else
{payaftertnd = payafterOT - (.15 * payafterOT);}
cout << fixed << showpoint << setprecision(2);
paystub<< fixed << showpoint << setprecision(2);
paystub << "Their pay for this week will be $" << payaftertnd << endl;
}
void closeSeq(char endProg)
{
cout << "Do you wish to enter another employee's information? Enter x (lowercase required) if not," << endl;
cout << " enter any other character to continue." << endl;
cin >> endProg;
if (endProg == 'x')
{
dontEnd != true;
/// Add stuff later
}
else
{
dontEnd= true;
}
}
// -------------------------------------------------------------------
// -------------------------------------------------------------------
// ------- Main -------
int main()
{
openStub(paystub);
filecheck(paystub);
gatherinfo(fName, lName, jTitle);
payamount( dClaim, hrWorked, ID, hrWage, otPay, payafterOT, otHours, tax, payaftertnd, deduc);
closeSeq(endProg);
}
|