Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- using namespace std;
- const float FEDERALWITH_TAXRATE =.18;
- const float STATEWITH_TAXRATE = .045;
- const float SOCIALSEC_WITHHOLD = .02;
- const int Size = 30;
- typedef long int employee[Size];
- typedef int intarray[Size];
- typedef float fltarray[Size];
- typedef string strarray[Size];
- int setdata(employee,strarray,intarray,fltarray,ifstream &,fltarray,fltarray,fltarray,fltarray,fltarray,int &);
- float findgross(intarray,fltarray,fltarray,int,float &);
- void printdata(const employee,const strarray,const intarray,const fltarray, const fltarray,
- const fltarray, const fltarray);
- void findwithholding(fltarray,int,float,fltarray);
- int main()
- {
- employee id;
- int num = 0, count;
- float totalgross;
- strarray name;
- intarray hours;
- fltarray rate,gross,net,taxes,social,state;
- ifstream fin("empdata.txt");
- count = setdata(id,name,hours,rate,fin,gross,net,taxes,social,state,num);
- findgross(hours,rate,gross,count,totalgross);
- findwithholding(gross, count,FEDERALWITH_TAXRATE, taxes);
- findwithholding(gross, count, STATEWITH_TAXRATE, state);
- findwithholding(gross, count, SOCIALSEC_WITHHOLD, social);
- printdata(id,name,hours,rate,gross,net,taxes);
- return 0;
- }
- int setdata(employee id,strarray name,intarray hrs,fltarray rate,ifstream & fin,
- fltarray gross,fltarray net,fltarray taxes,fltarray social,fltarray state,int &i)
- {
- //int i = 0;
- fin>>id[i];
- while(id[i]!=0){
- fin.get();
- getline(fin, name[i]);
- fin>>hrs[i];
- fin>>rate [i];
- i++;
- fin>>id[i];
- /*for(int i = 0; i < Size; i++)
- { fin >> id[i]>>hrs[i]>>rate[i];
- calc(hrs[i],rate[i],gross[i],taxes[i],state[i],social[i],net[i]);
- }*/
- }
- return i;
- }
- float findgross(intarray hrs, fltarray rate, fltarray gross, int count,float &totalgross)
- {
- for (int i = 0; i < count; i++)
- {
- gross[i] = rate[i]*hrs[i];
- totalgross += gross[i];
- }
- return totalgross;
- }
- void findwithholding(fltarray gross, int count, float withhold, fltarray income)
- {
- for (int i = 0; i < count; i++)
- {
- income[i] = gross[i]*withhold;
- }
- }
- /*void findgross(int hours, float payrate, float &grosspay,float &fedtax,float &statetax,float &soc_withhold,float &netpay)
- { grosspay = hours * payrate;
- fedtax = grosspay * FEDERALWITH_TAXRATE;
- statetax = grosspay * STATEWITH_TAXRATE;
- soc_withhold = grosspay * SOCIALSEC_WITHHOLD;
- netpay = (grosspay - (fedtax+statetax+soc_withhold));
- }*/
- void printdata(const employee id,const strarray name,const intarray hrs,const fltarray rate,
- const fltarray gross,const fltarray net,const fltarray taxes)
- { //cout <<setiosflags(ios::fixed|ios::showpoint)<<setprecision(2);
- for(int j = 0; j < Size; j++)
- {
- cout << setprecision(2);
- cout << left << setw(15) << "Employee ID";
- cout << right << setw(20) << "Employee Name";
- cout << right << setw(20) << "Employee Hours";
- cout << right << setw(20) << "Employee Rate";
- cout << right << setw(20) << "Employee Gross Pay";
- cout << right << setw(20) << "Employee Net Pay";
- cout << endl;
- for(int j=0;j<Size;j++){
- cout << left << setw(15) <<id[j];
- cout << right << setw(20) <<name[j];
- cout << right << setw(20) <<hrs[j];
- cout << right << setw(20) <<rate[j];
- cout << right << setw(20) <<gross[j];
- cout << right << setw(20) <<net[j] <<endl;
- }
- //cout <<setw(10)<< id[i]<<setw(8)<<name[i]<<setw(6)<<hrs[i]<<setw(4)<<rate[i];
- //cout << setw(10)<<gross[i] <<setw(8)<< net[i]<<endl;
- //cout << id[i] << " " << name[i] <<" " <<hrs[i] <<" " <<rate[i] << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement