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
|
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int readindata(char firstname[][15], char lastname[][15], char taxstatus[][2], int employeeid[], float hoursworked[], float hourlyrate[], int counter);
void grosspaycalc (float hoursworked[], float hourlyrate[], float overtimehours[], float overtimepay[], float grospay[], int counter);
void taxongrosspay(float grosspay[], float taxrat[], int counter);
void taxonstatus(char taxstatus[][2], float grosspay[], float taxrate[], int counter);
void netpaycalc(float taxamount[], float grosspay[], float taxrate[], float netpay[], int counter);
void finaloutput(char firstname[][15], char lastname[][15], char taxstatus[][2], int employeeid[], float hoursworked[], float hourlyrate[], float overtimehours[], float overtimepay[], float grosspay[], float taxrate[], float taxamount[], float netpay[], int counter);
int main(){
const int MAXSIZE=100;
int employeeid[MAXSIZE];
float hourlyrate[MAXSIZE], taxamount[MAXSIZE], netpay[MAXSIZE], grosspay[MAXSIZE], hoursworked[MAXSIZE], overtimehours[MAXSIZE], overtimepay[MAXSIZE], taxrate[MAXSIZE];
char firstname[MAXSIZE][15], lastname[MAXSIZE][15], taxstatus[MAXSIZE][2];
int counter;
counter= readindata(firstname, lastname, taxstatus, employeeid, hoursworked, hourlyrate, MAXSIZE);
grosspaycalc(hoursworked, hourlyrate, overtimehours, overtimepay, grosspay, counter);
taxongrosspay(grosspay, taxrate, counter);
taxonstatus(taxstatus, grosspay, taxrate, counter);
netpaycalc(taxamount, grosspay, taxrate, netpay, counter);
finaloutput(firstname, lastname, taxstatus, employeeid, hoursworked, hourlyrate, overtimehours, overtimepay, grosspay, taxrate, taxamount, netpay, counter);
}//END MAIN
int readindata(char firstname[][15], char lastname[][15], char taxstatus[][2], int employeeid[], float hoursworked[], float hourlyrate[], int counter){
ifstream myfile;
myfile.open("/Users/Guest/Documents/payrollclass.txt");
counter=0;
while (myfile>>firstname[counter]>>lastname[counter]>>employeeid[counter]>>taxstatus[counter]>>hoursworked[counter]>>hourlyrate[counter]) {
counter=counter+1;
}//END WHILE
myfile.close();
return counter;
}//END READINDATA
void grosspaycalc (float hoursworked[], float hourlyrate[], float overtimehours[], float overtimepay[], float grosspay[], int counter){
for (int i=0; i<counter; i=i+1) {
if (hoursworked[i]>40){
overtimehours[i]=hoursworked[i]-40;
overtimepay[i]=1.5*overtimehours[i]*hourlyrate[i];
grosspay[i]=overtimepay[i]+(hoursworked[i]*hourlyrate[i]);
}//END IF
else {
overtimepay[i]=0;
overtimehours[i]=0;
grosspay[i]=hourlyrate[i]*hoursworked[i];
}//END ELSE
}//END FOR
}//END GROSSPAYCALC
void taxongrosspay(float grosspay[], float taxrate[], int counter){
for (int i=0; i<counter; i=i+1) {
if (grosspay[i]>1000) {
taxrate[i]=.30;
}//END IF
if (grosspay[i]>800 && grosspay[i]<=1000) {
taxrate[i]=.20;
}//END IF
if (grosspay[i]>500 && grosspay[i]<=800) {
taxrate[i]=.10;
}//END IF
if (grosspay[i]>=0 && grosspay[i]<=500) {
taxrate[i]=0;
}//END IF
}//END FOR
}//END TAXONGROSSPAY
void taxonstatus (char taxstatus[][2], float grosspay[], float taxrate[], int counter){
for (int i=0; i<counter; i=i+1) {
if ((((strcmp(taxstatus[i],"H")==0))||((strcmp(taxstatus[i], "h")==0)))&&(grosspay[i]>500)){
taxrate[i]=taxrate[i]-.05;
}//END IF
if (((strcmp(taxstatus[i],"S")==0))||((strcmp(taxstatus[i], "s")==0))){
taxrate[i]=taxrate[i]+.05;
}//END IF
if (((strcmp(taxstatus[i],"S")==0))||((strcmp(taxstatus[i], "s")==0))){
taxrate[i]=taxrate[i];
}//END IF
}//END FOR
}//END TAXONSTATUS
void netpaycalc(float taxamount[], float grosspay[], float taxrate[], float netpay[], int counter){
for (int i=0; i<counter; i=i+1) {
taxamount[i]=grosspay[i]*taxrate[i];
netpay[i]=grosspay[i]-taxamount[i];
}//END FOR
}//END NETPAYCALC
void finaloutput (char firstname[][15], char lastname[][15], char taxstatus[][2], int employeeid[], float hoursworked[], float hourlyrate[], float overtimehours[], float overtimepay[], float grosspay[], float taxrate[], float taxamount[], float netpay[], int counter){
cout<<setw(55)<<"Melissa Inc. Payroll"<<endl;
cout<<setiosflags(ios::fixed|ios::showpoint|ios::left)<<setprecision(2);
cout<<setw(15)<<"First Name"<<setw(15)<<"Last Name"<<setw(15)<<"Tax Status"<<setw(15)<<"Employee ID"<<setw(15)<<"Hours Worked"<<setw(15)<<"Hourly Rate"<<setw(15)<<"Overtime Hours"<<setw(15)<<"Overtime Pay"<<setw(15)<< "Gross Pay"<<setw(15)<<"Tax Rate"<<setw(15)<<"Tax Amount"<<setw(15)<<"Net Pay"<<endl;
for (int i=0; i<counter; i=i+1) {
cout<<setw(15)<<firstname[i]<<setw(15)<<lastname[i]<<setw(15)<<taxstatus[i]<<setw(15)<<employeeid[i]<<setw(15)<<hoursworked[i]<<setw(15)<<hourlyrate[i]<<setw(15)<<overtimehours[i]<<setw(15)<<overtimepay[i]<<setw(15)<<grosspay[i]<<setw(15)<<taxrate[i]<<setw(15)<<taxamount[i]<<setw(15)<<netpay[i]<<endl;
}//END FOR
}//END FINALOUTPUT
|