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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
#include<fstream>
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
class payroll{
ifstream fin;
int n;
public:
char *fname, *lname;
char paystat, maritalstatus, employeeid;
float taxrate;
double hoursworked, overtimehours, regularhours, othr;
double reghourlyrate,regularpay,totalnetpay,minnp,maxnp;
double avgnetpay,taxamount,netpay,grosspay,overtimepay;
virtual double findgrosspay();
//changed the prototype to accept pointers
void setvariables(char*, char*, char, char, char, double, double);
virtual double findtaxamount();
virtual double findnetpay();
virtual double findavgnetpay();
void printheadings();
void printdata();
double minnet(double, int);
double maxnet(double, int);
void printminmax(double, double);
void printreport();
void sortbypointers(void);
payroll();
~payroll();
};
class hourly: public payroll{
public: double findgrosspay(){
if(hoursworked>40){
overtimehours=hoursworked-40;
othr=reghourlyrate*1.5;
regularpay=hoursworked*reghourlyrate;
overtimepay=overtimehours*(reghourlyrate*1.5);
grosspay=regularpay+overtimepay;
}
else{
grosspay=hoursworked*reghourlyrate;
regularpay=grosspay;
overtimehours=0;
overtimepay=0;
return grosspay;
}//IF
};//findgrosspay
};
class salaried: public payroll{
public: double findgrosspay(){
if(hoursworked>0){
overtimepay=hoursworked*(regularpay/52/40);
regularpay=reghourlyrate/52;
grosspay=regularpay+overtimepay;
return grosspay;
}//If
};//findgrosspay
};
payroll::payroll(){
fin.open("exp.txt"); }
payroll::~payroll() {
fin.close();}
double payroll::findtaxamount()
{
taxrate=.30;
taxamount=grosspay*taxrate;
return taxamount;
}//findtaxamount
double payroll::findgrosspay()
{
if(hoursworked>0)
{
overtimepay=hoursworked*(regularpay/52/40);
regularpay=reghourlyrate/52;
grosspay=regularpay+overtimepay;
return grosspay;
}//If
}//findgrosspay
double payroll::findnetpay()
{
netpay=grosspay-taxamount;
totalnetpay=totalnetpay+netpay;
return netpay;
}//findnetpay
double payroll::findavgnetpay()
{
avgnetpay=totalnetpay/n;
cout<<endl<<"The average net pay for "<<n<<" employees is "
<<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<avgnetpay<<endl;
return avgnetpay;
}//findavgnetpay
double payroll::minnet(double minnp, int n)
{
if(n==0)
{
minnp=1000000;
}
if(netpay<minnp) {minnp=netpay;}
cout<<endl<<"The minimum net pay for "<<n<<" employees is "
<<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<minnp<<endl;
return minnp;
}//minnet
double payroll::maxnet(double maxnp, int n)
{
if(n==0) {maxnp=5000000;}
if(netpay>maxnp) {maxnp=netpay;}
cout<<endl<<"The maximum net pay for "<<n<<" employees is "
<<setw(8)<<setprecision(2)<<fixed<<left<<showpoint<<maxnp<<endl;
return maxnp;
}//maxnp
void payroll:: sortbypointers()
{
cout << "Before sorting by pointer:" << endl;
double p[100];
int i,j;
double temp;
int sortedflag=0;
for(i=0;i<n;i++) p[i]=netpay+i; //INITIALIZING POINTER ARRAY
for(i=0;i<n;i++)cout<< "$" << p[i]<<" ";
while (!sortedflag)
{
sortedflag=1;
for(j=0;j<n-1;j++ )
{
if (p[j]>p[j+1])
{
temp=p[j];
p[j]=p[j+1];
p[j+1]=temp;
sortedflag=0;
}//SWAP
}//J
}//I
cout<<endl<<"SORTED ARRAY:";
for(i=0;i<n;i++)cout<<p[i]<<" ";
}//sortfunction
//changed here to accept char arrays for fname and lname
void payroll::setvariables(char *afname, char *alname, char amaritalstatus, char aemployeeid,
char apaystat, double ahoursworked, double areghourlyrate)
{
fname = afname;
lname = alname;
maritalstatus = amaritalstatus;
employeeid = aemployeeid;
paystat = apaystat;
hoursworked = ahoursworked;
reghourlyrate = areghourlyrate;
}// setvariables
void payroll::printheadings(){
cout<<endl<<setw(15)<<"EMP ID"<<setw(16)<<"FIRST NAME"<<setw(15)<<"LAST NAME"<<setw(8)<<"PAY STAT"<<setw(8)<<"MARITAL STAT"<<setw(8)<<"HW"<<setw(9)<<"RHR"<<setw(9)<<"OTHR"<<setw(9)<<"OTH"<<setw(9)<<"OTP"<<setw(10)<<"REGPAY"<<setw(11)<<"GROSS PAY"<<setw(8)<<"TR"<<setw(9)<<"TA"<<setw(9)<<"NET PAY"<<endl;
cout<<setw(15)<<"==========="<<setw(16)<<"=========="<<setw(15)<<"========="<<setw(8)<<"========"<<setw(8)<<"=="<<setw(8)<<"=="<<setw(9)<<"==="<<setw(9)<<"===="<<setw(9)<<"==="<<setw(9)<<"==="<<setw(10)<<"===="<<setw(11)<<"=="<<setw(8)<<"=="<<setw(9)<<"=="<<setw(9)<<"=="<<endl;
}//PRINTHEADINGS
void payroll::printdata(){
cout<<setw(15)<<employeeid<<setw(16)<<fname<<setw(15)<<lname<<setw(8)<<paystat<<setw(8)<<maritalstatus<<setw(8)<<hoursworked<<setw(9)<<reghourlyrate<<setw(9)<<othr<<setw(9)<<overtimehours<<setw(9)<<overtimepay<<setw(10)<<regularpay<<setw(11)<<grosspay<<setw(8)<<taxrate<<setw(9)<<taxamount<<setw(9)<<netpay
<<endl; }//PRINTDATA
void payroll::printreport()
{
n=0,totalnetpay=0;
printheadings();
fin.open("exp.txt");
while(fin>>employeeid>>fname>>lname>>paystat>>maritalstatus>>hoursworked>>reghourlyrate)
{
cout<<"in here 1";
findgrosspay();
cout<<"in here 2";
findtaxamount();
cout<<"in here 3";
findnetpay();
printdata();
sortbypointers();
n++;
}//WHILE
avgnetpay=findavgnetpay();
cout<<"The average net pay for "<<n<<" employees is $"<<avgnetpay<<endl;
}//PRINTREPORT
int main(){
payroll *employee[8], *report = new payroll;
//employee[8]->printreport();
int i=0;
char afname[14], alname[16], apaystat, amaritalstatus, aemployeeid;
double ahoursworked, areghourlyrate, minnp,maxnp, netpays[8];
void sortnetpays(double netpays[], int i);
ifstream fin;
fin.open("exp.txt");
while(fin>>aemployeeid>>afname>>alname>>apaystat>>amaritalstatus>>ahoursworked>>areghourlyrate)
{
if(apaystat=='s')
{
employee[i]=new salaried();
employee[i]->setvariables(afname, alname, apaystat, amaritalstatus, aemployeeid, ahoursworked, areghourlyrate);
}//if s
if(apaystat=='h')
{
employee[i]=new hourly();
employee[i]->setvariables(afname, alname, apaystat, amaritalstatus, aemployeeid, ahoursworked, areghourlyrate);
}//if h
employee[i]->findgrosspay();
employee[i]->findtaxamount();
netpays[i]=employee[i]->findnetpay();
minnp = employee[i]->minnet(minnp, i);
maxnp = employee[i]->maxnet(maxnp, i);
report->printheadings();
employee[i]->printdata();
i++;
}//WHILE
fin.close();
//system ("pause");
}//MAIN
|