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 164 165 166 167 168 169 170 171 172 173 174 175 176
|
#include<iostream>
#include<fstream>
#include <iomanip>
using namespace std;
struct person{
char ms;
char firstname;
char lastname;
long int id;
int hoursworked;
int overtimehours;
int regularhours;
float hourlyrate;
float regularpay;
float overtimepay;
float grosspay;
float taxrate;
float taxamount;
float netpay; };
int readalldata( person[ ], const int );
void findovertimehours( person[ ], int );
void findovertimepay( person[ ], int );
void findregularhours( person[ ], int );
void findregularpay( person[ ], int );
void findgrosspay( person[ ], int );
void findtaxrate( person[ ], int );
void findtaxamount( person[ ], int );
void findnetpay( person[ ], int );
void sortbypointers(person[ ], int);
void printalldata( person[ ], int );
int main( ){
const int MAXSIZE = 100;
int n;
person employee[ MAXSIZE ];
n = readalldata( employee, MAXSIZE );
findovertimehours( employee, n );
findovertimepay( employee, n );
findregularhours( employee, n );
findregularpay( employee, n );
findgrosspay( employee, n );
findtaxrate( employee, n );
findtaxamount( employee, n );
findnetpay( employee, n );
sortbypointers(employee,n);
printalldata(employee,n);
return 0;
}
int readalldata( person emp[ ], int n ){
ifstream fin( "payroll.in" );
n = 0;
while( fin >> emp[ n ].firstname >> emp[ n ].lastname >> emp[ n ].hoursworked >> emp[ n ].hourlyrate ){
n++; }
fin.close( );
return n;
}
void findovertimehours( person emp[ ], int n ){
for( int i = 0 ; i < n ; i++){
if( emp[ i ].hoursworked > 40 )
emp[ i ].overtimehours = emp[ i ].hoursworked - 40;
else
emp[ i ].overtimehours = 0;
}
}
void findovertimepay( person emp[ ], int n ){
for( int i = 0 ; i < n ; i++){
emp[ i ].overtimepay = emp[ i ].overtimehours * emp[ i ].hourlyrate * 1.5;
}
}
void findregularhours( person emp[ ], int n ){
for( int i = 0 ; i < n ; i++){
if( emp[ i ].hoursworked > 40 ) emp[ i ].regularhours = 40;
else emp[ i ].regularhours = emp[ i ].hoursworked;
}
}
void findregularpay( person emp[ ], int n ){
for( int i = 0 ; i < n ; i++ ){
emp[ i ].regularpay = emp[ i ].regularhours * emp[ i ].hourlyrate;
}
}
void findgrosspay( person emp[ ], int n ){
for( int i = 0 ; i < n ; i++){
emp[ i ].grosspay = emp[ i ].regularpay + emp[ i ].overtimepay;
}
}
void findtaxrate( person emp[ ], int n ){
for( int i = 0 ; i < n ; i++){
if( emp[ i ].grosspay > 1000.00 ) emp[ i ].taxrate = 0.30;
else if( emp[ i ].grosspay >800.00 ) emp[ i ].taxrate = 0.20;
else if( emp[ i ].grosspay > 500.00 ) emp[ i ].taxrate = 0.10;
else emp[ i ].taxrate = 0.0;
if (emp[ i ].ms=='S') emp[ i ].taxrate=(emp[ i ].taxrate+.05);
else if (emp[ i ].ms=='s') emp[ i ].taxrate=(emp[ i ].taxrate+.05);
else if (emp[ i ].ms=='H' && emp[ i ].grosspay > 500.00 ) emp[ i ].taxrate=(emp[ i ].taxrate-.05);
else if (emp[ i ].ms=='h' && emp[ i ].grosspay > 500.00 ) emp[ i ].taxrate=(emp[ i ].taxrate-.05);
else emp[ i ].taxrate=(emp[ i ].taxrate*1);
}
}
void findtaxamount( person emp[ ], int n ){
for( int i = 0 ; i < n ; i++){
emp[ i ].taxamount = emp[ i ].grosspay * emp[ i ].taxrate;
}
}
void findnetpay( person emp[ ], int n ){
for( int i = 0 ; i < n ; i++){
emp[ i ].netpay = emp[ i ].grosspay - emp[ i ].taxamount;
}
}
void sortbypointers(person emp[ ], int n){
int i,j;
float *p[n];
char *q[n];
char *k[n];
double temp;
char tempa;
char tempb;
int sortedflag=0;
for(i=0;i<n;i++){
p[i]=&emp[ i ].netpay;
q[i]=&emp[ i ].firstname;
k[i]=&emp[ i ].lastname;
while (!sortedflag){
sortedflag=1;
for(j=0;j<n-i;j++ ){
if (*p[j]>*p[j+1]){
temp=*p[j];
*p[j]=*p[j+1];
*p[j+1]=temp;
tempa=*q[j];
*q[j]=*q[j+1];
*q[j+1]=tempa;
tempb=*k[j];
*k[j]=*k[j+1];
*k[j+1]=tempb;
sortedflag=0; } // if
} // for
} // while
}
}
void printalldata( person emp[ ], int n ){
cout<<setw(16)<<"FIRST NAME"<<setw(18)<<"LAST NAME"<<setw(8)<<"NET"<<endl;
for( int i = 0 ; i < n; i++){
cout<<setw(16)<<emp[ i ].firstname<<setw(18)<<emp[ i ].lastname<<setw(8)emp[ i ].netpay<<endl;
}
system ("pause");}
|