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
|
//------------------------------------------------------------------------
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
const int MAX_EMP = 25;
const int MAX_TAX = 5;
const float TAX_1000 = .035;
const float TAX_2000 = .06;
const float TAX_4000 = .085;
const float TAX_LUX = .12;
const int MAX_OVERTIME = 60;
const int MAX_NORMAL_HOURS = 40;
void GetTaxTable(float taxable[], float taxrate[], int& numTax);
void GetEmpHours(int empid[], int hours[], float hourlyrate[], int& numEmp);
void PrintHeader(int numEmp);
void ProcessPayRoll(const int empid[], const int hours[],
const float hourlyrate[], int numEmp,
const float taxable[], const float taxrate[],
int numTax);
bool OverHoursLimit(int hours);
int FindTaxLevel(float wages, const float taxable[], int size);
float ComputeWages(int hours[], float hourlyrate[]);
void PrintEmpWages(int empid, float wages, float rate, float netpay);
int main ()
{
while(!cin.eof())
{
float taxable[MAX_TAX], taxrate[MAX_TAX], hourlyrate[MAX_EMP];
int empid[MAX_EMP], hours[MAX_EMP], numEmp = 0, numTax = 0;
cout << "Enter the number of levels for the tax table:" << endl;
cin >> numTax;
GetTaxTable(taxable, taxrate, numTax);
cout << "Enter the number of empliees to process:" << endl;
cin >> numEmp;
GetEmpHours(empid, hours, hourlyrate, numEmp);
PrintHeader(numEmp);
ProcessPayRoll(empid, hours, hourlyrate, numEmp, taxable, taxrate, numTax);
}
return 0;
}
void GetTaxTable(float taxable[],float taxrate[], int& numTax)
{
int length = numTax;
for (int index = 0; index < length; index++)
{
cout << "Enter taxable wages and tax rates:" << endl;
cin >> taxable[index];
cin >> taxrate[index];
}
}
void GetEmpHours(int empid[], int hours[], float hourlyrate[], int& numEmp)
{
int size = numEmp;
for (int k = 0; k < size; k++)
{
cout << "Enter employee ID, hours and hourly rate:" << endl;
cin >> empid[k];
cin >> hours[k];
cin >> hourlyrate[k];
}
}
void PrintHeader(int numEmp)
{
cout << "Employee Payroll with" << numEmp << "entries./n" << endl;
cout << setw(6) << "EmpID" << setw(8) << "Gross Pay"
<< setw(8) << "Tax Rate" << setw(8) << "Net Pay" << endl;
cout << "------" << setw(9) << "---------" << setw(8)
<< "---------" << setw(8) << "---------" << endl;
}
void ProcessPayRoll(const int empid[], const int hours[],
const float hourlyrate[], int numEmp,
const float taxable[], const float taxrate[],
int numTax)
{
float wages, taxes = 0.0, netpay = 0.0;
int index = 0;
for(int n = 0; n < numEmp; n++)
{
wages = ComputeWages(hours[n], hourlyrate[n]);
netpay = wages - taxes;
index = FindTaxLevel(wages, taxable[n], numTax);
taxes = wages * taxrate[index];
PrintEmpWages(empid[n],wages,hourlyrate[n],netpay);
}
}
bool OverHoursLimit(int hours)
{
if (hours > MAX_OVERTIME)
return true;
else
return false;
}
int FindTaxLevel(float wages, const float taxable[], int size)
{
for (int i = 0; i < size; i++)
if (taxable[i] <= wages)
return i;
return -1;
}
float CompeterWages(int hours[], float hourlyrate[])
{
float grossPay = 0.0;
int overTime = 0;
for (int h = 0; h < MAX_EMP; h++)
{
if (OverHoursLimit(hours[h]) == true)
cout << "Abnormal overtime hours! Unable to process!!" << endl;
if (hours[h] > MAX_NORMAL_HOURS)
{
overTime = hours[h] - MAX_NORMAL_HOURS;
grossPay = (overTime * hourlyrate[h] * 1.5) + (MAX_NORMAL_HOURS * hourlyrate[h]);
}
else
grossPay = hours[h] * hourlyrate[h];
}
return grossPay;
}
void PrintEmpWages(int empid, float wages, float rate, float netpay)
{
cout << setw(6) << empid
<< setw(3) << wages
<< setw(5) << rate
<< setw(5) << netpay
<< endl;
}
|