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
|
#include "employee.h"
//Declaring constants
const int WEEK_MAX = 40;
const double FED_TAX = 0.20;
const double STATE_TAX = 0.075;
const double OVER_TIME = 1.5;
const char delim = '\t';
const char space = ' ';
//Declaring variables
double netPay;
double fedTotal;
double stateTotal;
double payCheck;
double overHours;
double overPay;
double regularPay;
Employee::Employee()
{
employeeNumber = 0;
employeeName = "";
employeeAddress = "";
phoneNumber = "";
hourlyWage = 0.00;
weeklyHours = 0.00;
}
Employee::Employee(int eNumber, string eName, string eAddress, string pNumber, double hWage, double wHours)
{
employeeNumber = eNumber;
employeeName = eName;
employeeAddress = eAddress;
phoneNumber = pNumber;
hourlyWage = hWage;
weeklyHours = wHours;
}
bool Employee::readEmployee(ifstream& input)
{
if (getline(input, employeeNumber, space) && getline(input, employeeName, delim) && getline(input, employeeAddress, delim) && getline(input, phoneNumber, delim) && getline(input, hourlyWage, space) && getline(input, weeklyHours, '\n'))
{
return true;
}
else
{
return false;
}
}
void Employee::writeEmployee(ofstream& output)
{
//No error checking when writing a file
output << employeeNumber << space
<< employeeName << delim
<< employeeAddress << delim
<< phoneNumber << delim
<< hourlyWage << space
<< weeklyHours << '\n';
}
int Employee::getEmployeeNumber( ) const
{
return employeeNumber;
}
string Employee::getEmployeeName( ) const
{
return employeeName;
}
string Employee::getEmployeeAddress( ) const
{
return employeeAddress;
}
string Employee::getPhoneNumber( ) const
{
return phoneNumber;
}
double Employee::getHourlyWage( ) const
{
return hourlyWage;
}
double Employee::getWeeklyHours( ) const
{
return weeklyHours;
}
double Employee::getCalcPay( ) const
{
if (weeklyHours <= WEEK_MAX)
{
netPay = hourlyWage * weeklyHours;
fedTotal = netPay * FED_TAX;
stateTotal = netPay * STATE_TAX;
payCheck = ((netPay - fedTotal) - stateTotal);
}
else if (weeklyHours > WEEK_MAX)
{
overHours = weeklyHours - WEEK_MAX;
regularPay = WEEK_MAX * hourlyWage;
overPay = overHours * (hourlyWage * OVER_TIME);
netPay = regularPay + overPay;
fedTotal = netPay * FED_TAX;
stateTotal = netPay * STATE_TAX;
payCheck = ((netPay - fedTotal) - stateTotal);
}
return payCheck;
}
|