#include <iostream> #include <fstream> #include <iomanip> using namespace std; //function prototypes int readalldata(char[][15], char[][15], long int[], int[], float[], const int); void findregularhours(int[], int[], int); void findregularpay(int[], float[], float[], int); void findovertimehours(int[], int[], int); void findovertimepay(float[], float[], int[], int); void findgp(float[], float[], float[], int); void findtaxrate(float[], float[], int); void findtaxamount(float[], float[], float[], int); void findnetpay(float[], float[], float[], int); void printalldata(char[][15], char[][15], long int[], int[], float[], float[], float[], float[], float[], int); //end prototypes int main (){ const int maxNum=100; char firstname[10][15]; char lastname[10][15]; long int ei[maxNum]; float gp[maxNum],np[maxNum],otp[maxNum],tax[maxNum], hr[maxNum], tr[maxNum], rp[maxNum]; int hw[maxNum], oth[maxNum], rh[maxNum]; int n; float sum = 0; float average = 0; float netpay[maxNum] = {np[maxNum]}; //function calls n=readalldata(firstname, lastname, ei, hw, hr, maxNum); findregularhours(hw, rh, n); findregularpay(rh,rp, hr, n); findovertimehours(hw, oth, n); findovertimepay(otp, hr, oth, n); findgp(rp, otp, gp, n); findtaxrate(gp, tr, n); findtaxamount(tr, gp, tax, n); findnetpay(np, gp, tax, n); printalldata(firstname, lastname, ei, hw, hr, gp, tr, tax, np, n); for (int i=0; i<n; i++) sum+=netpay[i]; average = sum/np[maxNum]; cout<<"Average Netpay:"<<average<<endl; //end calls system ("pause"); return 0; }//MAIN //function definitions int readalldata( char firstname[][15], char lastname[][15], long int ei[], int hw[], float hr[], int n){ ifstream fin("employee.txt"); n=0; while(fin>>firstname[n]>>lastname[n]>>ei[n]>>hw[n]>>hr[n]) n++;//WHILE fin.close(); return n; }//READALLDATA void findregularhours(int hw[], int rh[], int n){ for (int i=0; i<n; i++){ if(hw[i]>40)rh[i]=40; else rh[i]=hw[i]; }//FOR }//findregularhours void findregularpay(int rh[], float rp[], float hr[], int n){ for (int i=0; i<n; i++){ rp[i]=rh[i]*hr[i]; }//FOR }//findregularpay void findovertimehours(int hw[], int oth[], int n){ for (int i=0; i<n; i++){ if(hw[i] > 40) oth[i] = hw[i] - 40; else oth[i] = 0; }//FOR }//end oth function void findovertimepay(float otp[], float hr[], int oth[], int n){ for (int i=0; i<n; i++){ otp[i] = oth[i] * hr[i] * 1.5; }//FOR }//end ot pay function void findgp(float rp[], float otp[], float gp[], int n){ for (int i=0; i<n; i++){ gp[i] = rp[i] + otp[i]; }//FOR }//end gp function void findtaxrate (float gp[], float tr[], int n){ for (int i=0; i<n; i++){ 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; }//FOR }//end taxrate function void findtaxamount(float tr[], float gp[], float tax[], int n){ for (int i=0; i<n; i++){ tax[i] = gp[i] * tr[i]; }//FOR }//end taxamount function void findnetpay (float gp[], float np[], float tax[], int n){ for (int i=0; i<n; i++){ np[i] = gp[i] - tax[i]; }//FOR }//end netpay function void printalldata(char firstname[][15], char lastname[][15], long int ei[], int hw[], float hr[], float gp[], float np[], float otp[], float tax[], int n) { cout<<setw(1)<<"First Name"<<setw(15)<<"Last Name"<<"\t"<<"Employee ID"<<"\t"<<"HW"<<"\t"<<"HR"<<"\t"<<"GP"<<"\t"<<"NP"<<"\t"<<"OTP"<<"\t"<<"Taxes"<<"\t"<<"\t"<<endl; cout<<"\n"<<endl; for (int i=0; i<n; i++){ cout<<setw(10)<<firstname[i]<<setw(15)<<lastname[i]<<setw(15)<<ei[i]<<"\t"<<hw[i]<<"\t"<<hr[i]<<"\t"<<gp[i]<<"\t"<<np[i]<<"\t"<<otp[i]<<"\t"<<tax[i]<<endl; }//FOR }//end printall function

This post has been edited by **L-uke**: 06 August 2009 - 09:31 AM