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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int id[100], i=0, n=0; //hours worked
double hw[100], rp[100], gp[100], otp[100], TR[100], ta[100], np[100]; //regular pay, gross, overtime pay, taxes, tax rate, net pay
double rh[100], oth[100], hr[100], otr[100]; //regular hours, overtime hours, hourly rate, overtime rate
char fn[100][14], ln[100][15], st[100]; //first name/last name/status-married, single, head of household
double tnp=0; // total net pay
double rc=0; // record counter
double avg=0; // average
//functions
void over(void){ //Overtime hours function
for (i=0; i<n;i++)
{
if(hw[i] > 40)
{
oth[i] = hw[i] - 40;
otr[i] = hr[i] * 1.5;
}
else
{
oth[i]=0, otr[i]=0;
}
}
}// END Overtime hours function
void pay(void){ // Pay function
for (i=0; i<n;i++)
{
rp[i] = 40 * hr[i];
if( oth[i] > 0)
otp[i] = (hw[i] - 40) * hr[i] * 1.5;
gp[i] = rp[i] + otp[i];
} // END Pay function
}
void tax(void){
for (i=0; i<n;i++) // Tax function
{
if( gp[i] > 1000 ) TR[i] = 0.30;
else if( gp[i] > 800) TR[i] = 0.20;
else if( gp[i] > 500) TR[i] = 0.10;
else TR[i] = 0.0;
if (st[i]=='S') TR[i] = (TR[i] + .05);
else if (st[i]=='M') TR[i] = (TR[i] * 1);
else if (st[i]=='H' && gp[i] > 500) TR[i] = (TR[i] - .05);
} // END Tax function
}
void net(void){
for (i=0; i<n;i++) //Net pay function
{
ta[i] = gp[i] * TR[i];
np[i] = gp[i] * (1.0- TR[i]);
tnp+=np[i];
rc++;
avg=tnp/rc;
} // END Net pay function
}
void swap(int x, int y)
{
int temp;
temp=id[x];
id[x]=id[y];
id[y]=temp;
int temp2;
temp2=hw[x];
hw[x]=hw[y];
hw[y]=temp2;
int temp3;
temp3=hr[x];
hr[x]=hr[y];
hr[y]=temp3;
int temp4;
temp4=otp[x];
otp[x]=otp[y];
otp[y]=temp4;
int temp5;
temp5=gp[x];
gp[x]=gp[y];
gp[y]=temp5;
int temp6;
temp6=ta[x];
ta[x]=ta[y];
ta[y]=temp6;
int temp7;
temp7=np[x];
np[x]=np[y];
np[y]=temp7;
}
void npSort (void){ //np sort function
bool flag=true;
int i;
while(flag==true)
{
flag=false;
for(i=1;i<rc;i++)
{
if(np[i]<np[i-1])
{
swap(i, i-1);
flag=true;
}
}
}
}
int main(){
int over();
int pay();
int tax();
int net();
ifstream fin ("employee.in");
while(fin>>id[n]>>hw[n]>>hr[n])n++;
over();
pay();
tax();
net();
cout<<endl<<endl<<"DR. EBRAHIMI'S PAYROLL INSTITUTE"<<endl<<endl;
cout<<"SSN #"<<"\t"<<"Hours"<<"\t"<<"Rate"<<"\t"<<"OverTime"<<"\t"<<"GrossPay"<<"\t"<<
"TaxRate"<<"\t"<<"NetPay"<<endl<<endl;
for (i=0; i<n;i++){
cout<<""<<id[i]<<"\t"<<hw[i]<<"\t"<<hr[i]<<"\t"<<otp[i]<<"\t\t"<<gp[i]<<"\t\t"
<<ta[i]<<"\t"<<np[i]<<endl<<endl;
}
cout<<"Employee Salary Total"<<endl;
cout<<tnp<<endl<<endl;
cout<<"Employee Salary Average"<<endl;
cout<<setprecision(5)<<avg<<endl<<endl;
npSort();
cout<<"Sorted Net Pay"<<endl;
for (i=0; i<n;i++){
cout<<""<<np[i]<<endl<<endl;}
return 0;
}//MAIN
|