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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
#include <iostream>
#include <fstream> // File Input/Output Stream
#include<iomanip>
#include <windows.h>
using namespace std;
float sum=0;
float average=0;
float c=0;
int n=0;
int readalldata(char[][10], char[][15], long int[],char [],int[],float[],const int);
void findoth(int[],float[],int);
void findotp(float[],float[],float[],int);
void findregh(int[],int[],int);
void findregp(int[],float[],float[],int);
void findgp(float[],float[],float[],int);
void findtaxr(float[],float[],char[], int);
void findtaxa(float[],float[],float[],int);
void findnp(float[],float[],float[],int);
float findaverage(float[],int);
int sort(char[][10], char[][15],long int[],char[],int[],float[],float[],float[],float[],float[],float[],float[],int);
void printalldata(char[][10], char[][15],long int[],char[],int[],float[],float[],float[],float[],float[],float[],float[],int);
int main(){
const int MAXSIZE=100;
int i=0;
char FName[MAXSIZE][10], LName[MAXSIZE][15], mstat[MAXSIZE];
long int id[MAXSIZE];
int hw[MAXSIZE];
float oth[MAXSIZE];
int regh[MAXSIZE];
float hr[MAXSIZE], regp[MAXSIZE];
float otp[MAXSIZE], gp[MAXSIZE];
float taxr[MAXSIZE], taxa[MAXSIZE], np[MAXSIZE];
n=readalldata(FName, LName, id, mstat, hw, hr, MAXSIZE);
findoth(hw,oth, n);
findotp(oth, hr, otp, n);
findregh(hw, regh, n);
findregp(regh, regp, hr, n);
findgp(regp, otp, gp, n);
findtaxr(gp, taxr, mstat, n);
findtaxa(gp, taxa, taxr, n);
findnp(gp, np, taxa, n);
findaverage(np,n);
printalldata(FName,LName,id,mstat,hw,hr,oth,otp,regp,gp,taxr,np,n);
sort(FName,LName,id,mstat,hw,hr,oth,otp,regp,gp,taxr,np,n);
system("PAUSE");
}
int readalldata(char FName[][10], char LName[][15], long int id[], char mstat[], int hw[], float hr[], int n){
ifstream fin("payroll.in");
n=0;
while(fin>>FName[n]>>LName[n]>>id[n]>>mstat[n]>>hw[n]>>hr[n]) n++;
fin.close();
return n;
}
void findoth(int hw[],float oth[], int n){
for(int i=0; i<n; i++){
if(hw[i]>40)oth[i]=hw[i]-40;
else oth[i]=0;
}
}
void findotp(float oth[], float hr[], float otp[], int n){
for(int i=0; i<n; i++){
otp[i]=oth[i]*hr[i]*1.5;
}
}
void findregh(int hw[], int regh[], int n){
for(int i=0; i<n; i++){
if(hw[i]>40) regh[i]=40;
else regh[i]=hw[i];
}
}
void findregp(int regh[], float regp[], float hr[], int n){
for(int i=0; i<n; i++){
regp[i]=regh[i]*hr[i];
}
}
void findgp(float regp[], float otp[], float gp[], int n){
for(int i=0; i<n; i++){
gp[i]=regp[i]+otp[i];
}
}
void findtaxr(float gp[], float taxr[], char mstat[], int n){
for(int i=0; i<n; i++){
if(gp[i]>1000.00)taxr[i]=.30;
else if(gp[i]>800.00) taxr[i]=.20;
else if(gp[i]>500.00) taxr[i]=.10;
else taxr[i]=0;
if (mstat[i]=='S') taxr[i]=(taxr[i]+.05);
else if (mstat[i]=='s') taxr[i]=(taxr[i]+.05);
else if (mstat[i]=='H' && gp[i]>500) taxr[i]=(taxr[i]-.05);
else if (mstat[i]=='h' && gp[i]>500) taxr[i]=(taxr[i]-.05);
else if (mstat[i]=='M') taxr[i]=(taxr[i]*1);
else if (mstat[i]=='m') taxr[i]=(taxr[i]*1);
}
}
void findtaxa(float gp[], float taxa[], float taxr[], int n){
for(int i=0; i<n; i++){
taxa[i]=gp[i]*taxr[i];
}
}
void findnp(float gp[], float np[], float taxa[], int n){
for(int i=0; i<n; i++){
np[i]=gp[i]-taxa[i];
}
}
float findaverage(float np[], int n){
for(int i=0; i<n;i++){
sum=sum + np[i];
c=c+1;
average = sum/c;
}
}
int sort(char FName[][10], char LName[][15], long int id[], char mstat[], int hw[],
float hr[], float oth[], float otp[], float regp[],
float gp[], float taxr[], float np[], int n){
int i,j;
for(int i=0; i<n-1; i++){
for(j=n-1; j>i; j--){
if(np[j]<np[j-1]){
float hold = (FName[j][10], LName[j][15], id[j], mstat[j], hw[j],
hr[j], oth[j], otp[j], regp[j],
gp[j], taxr[j], np[j]);
(FName[j][10], LName[j][15], id[j], mstat[j], hw[j],
hr[j], oth[j], otp[j], regp[j],
gp[j], taxr[j], np[j]) = (FName[j-1][10], LName[j-1][15], id[j-1], mstat[j-1], hw[j-1],
hr[j-1], oth[j-1], otp[j-1], regp[j-1], gp[j-1], taxr[j-1], np[j-1]);
(FName[j-1][10], LName[j-1][15], id[j-1], mstat[j-1], hw[j-1],
hr[j-1], oth[j-1], otp[j-1], regp[j-1],
gp[j-1], taxr[j-1], np[j-1]) = hold;
}//
}//
}//
cout<<"Sorted Data"<<endl<<endl;
cout<<setw(8)<<left<<"FIRST"<<setw(9)<<"LAST"<<setw(6)<<"ID"<<setw(6)<<"STAT"<<setw(4)<<"HW"<<
setw(5)<<"HR"<<setw(4)<<"OTH"<<setw(6)<<"OTP"<<setw(8)<<"REGP"<<setw(8)<<"GROSS"<<setw(6)<<"TAX"<<
setw(8)<<"NET"<<endl;
cout<<setw(8)<<left<<"====="<<setw(9)<<"===== "<<setw(6)<<"===="<<setw(6)<<"===="<<setw(4)<<"==="<<
setw(5)<<"==="<<setw(4)<<"==="<<setw(6)<<"==="<<setw(8)<<"====="<<setw(8)<<"====="<<setw(6)<<"===="
<<setw(3)<<"====="<<endl;
for(i=0;i<n;i++){
cout<<setw(8)<<FName[i]<<setw(9)<<LName[i]<<setw(6)<<id[i]<<setw(6)<<mstat[i]<<setw(4)<<hw[i]
<<setw(5)<<hr[i]<<setw(4)<<oth[i]<<setw(6)<<otp[i]<<setw(8)<<regp[i]
<<setw(8)<<gp[i]<<setw(6)<<taxr[i]<<setw(1)<<"$"<<np[i]
<<endl<<endl;
}
}
void printalldata(char FName[][10], char LName[][15], long int id[], char mstat[], int hw[],
float hr[], float oth[], float otp[], float regp[],
float gp[], float taxr[], float np[], int n){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
cout<<"\t \t \t MY PAYROLL PROGRAM"<<endl<<endl;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
cout<<"Unsorted Data"<<endl<<endl;
cout<<setw(8)<<left<<"FIRST"<<setw(9)<<"LAST"<<setw(6)<<"ID"<<setw(6)<<"STAT"<<setw(4)<<"HW"<<
setw(5)<<"HR"<<setw(4)<<"OTH"<<setw(6)<<"OTP"<<setw(8)<<"REGP"<<setw(8)<<"GROSS"<<setw(6)<<"TAX"<<
setw(8)<<"NET"<<endl;
cout<<setw(8)<<left<<"====="<<setw(9)<<"===== "<<setw(6)<<"===="<<setw(6)<<"===="<<setw(4)<<"==="<<
setw(5)<<"==="<<setw(4)<<"==="<<setw(6)<<"==="<<setw(8)<<"====="<<setw(8)<<"====="<<setw(6)<<"===="
<<setw(3)<<"====="<<endl;
for(int i=0; i<n;i++){
cout<<setw(8)<<FName[i]<<setw(9)<<LName[i]<<setw(6)<<id[i]<<setw(6)<<mstat[i]<<setw(4)<<hw[i]
<<setw(5)<<hr[i]<<setw(4)<<oth[i]<<setw(6)<<otp[i]<<setw(8)<<regp[i]
<<setw(8)<<gp[i]<<setw(6)<<taxr[i]<<setw(1)<<"$"<<np[i]
<<endl<<endl;
}
cout<<setw(8)<<"The Total Net Pay is: $"<<sum<<endl;
cout<<setw(8)<<"The Average Net Pay is: $"<<average<<endl<<endl;
}
|