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
|
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
class payroll {
ifstream fin;
public: string employeename;
char maritalstatus, paystat;
int employeeid, i;
float taxrate;
double hoursworked, overtimehours, regularhours;
double hourlyrate, regularpay, minnp, maxnp;
double avgnetpay, taxamount, netpay, grosspay, overtimepay;
virtual double findgrosspay();
void setvariables(char[], int, char, char, double, double, int);
void findtaxamount();
double findnetpay();
void printheaders();
void printdata();
double highlownetpay(double, double, double);
payroll();
~payroll();
};
class hourly : public payroll {
public: double findgrosspay() {
if (hoursworked > 40 ) {
overtimehours = hoursworked - 40;
regularpay = hoursworked * hourlyrate;
overtimepay = overtimehours * (hourlyrate * 1.5);
grosspay = regularpay + overtimepay; }
else {
grosspay = hoursworked * hourlyrate;
regularpay = grosspay; }
return grosspay;
};// findgrosspay
};
class salaried : public payroll {
public: double findgrosspay() {
regularpay = hourlyrate / 52; //For salaried employees,
// hourlyrate is read in from input as annual salary.
overtimehours = hoursworked - 40;
grosspay = regularpay;
if (overtimehours > 0) {
overtimepay = overtimehours * (regularpay / 40);
grosspay = regularpay + overtimepay;
return grosspay;
}// If
};//findgrosspay
};
payroll::payroll() {
fin.open("payroll16.dat"); }
payroll::~payroll() {
fin.close(); }
void payroll::setvariables(char aemployeename[], int aemployeeid, char amaritalstatus,
char apaystat, double ahoursworked, double ahourlyrate, int i) {
employeename = aemployeename;
employeeid = aemployeeid;
maritalstatus = amaritalstatus;
paystat = apaystat;
hoursworked = ahoursworked;
hourlyrate = ahourlyrate;
}// setvariables
void payroll::findtaxamount() {
taxrate = .30;
taxamount = grosspay * taxrate;
}// findtaxamount
double payroll::findgrosspay() {
overtimehours = 0;
regularpay = 0;
overtimepay = 0;
grosspay = 0;
if (hoursworked > 40 ) {
overtimehours = hoursworked - 40;
regularpay = hoursworked * hourlyrate;
overtimepay = overtimehours * (hourlyrate * 1.5);
grosspay = regularpay + overtimepay; }
else
grosspay = hoursworked * hourlyrate;
regularpay = grosspay;
return grosspay;
}// findgrosspay
double payroll::findnetpay() {
netpay = grosspay - taxamount;
return netpay;
}// findnetpay
double payroll::highlownetpay(double netpay, double maxnp, double minnp) {
if (netpay < minnp) {minnp = netpay;}
if (netpay > maxnp) {maxnp = netpay;}
return minnp, maxnp;
}// highlownetpay
void payroll::printheaders() {
cout<<setw(45)<<"-PAYROLL REPORT-"<<endl<<endl;
cout<<" NAME ID HW OT RT-PAY OT-PAY GROSS"
" TAX NETPAY"<<endl;
cout<<"-----------------------------------------------------------------"<<endl;
}//printheaders
void payroll::printdata() {
cout<<setw(10)<<left<<employeename<<setw(4)<<employeeid;
cout<<setprecision(2)<<setiosflags(ios::fixed | ios::showpoint);
cout<<setw(6)<<right<<hoursworked<<setw(5)<<overtimehours<<setw(8)
<<regularpay<<setw(8)<<overtimepay<<setw(8)<<grosspay<<setw(8)
<<taxamount<<setw(8)<<netpay<<endl;
}//printdata
int main() {
payroll *employee[6], *report;
char aemployeename[14], amaritalstatus, apaystat;
int aemployeeid, i=0;
double ahoursworked, ahourlyrate;
double minnp=1000000, maxnp=0;
double avgnetpay, taxamount, netpay, grosspay, overtimepay;
report->printheaders();
ifstream fin;
fin.open("payroll16.dat");
while (fin>>aemployeename>>aemployeeid>>amaritalstatus>>apaystat
>>ahoursworked>>ahourlyrate) {
if (apaystat == 's') {
employee[i] = new salaried();
employee[i]->setvariables(aemployeename, aemployeeid, amaritalstatus,
apaystat, ahoursworked, ahourlyrate, i);
employee[i]->findgrosspay(); }// If s
if (apaystat == 'h') {
employee[i] = new hourly();
employee[i]->setvariables(aemployeename, aemployeeid, amaritalstatus,
apaystat, ahoursworked, ahourlyrate, i);
employee[i]->findgrosspay(); }// If h
employee[i]->findtaxamount();
employee[i]->findnetpay();
employee[i]->highlownetpay(netpay, maxnp, minnp);
employee[i]->printdata();
i++;
}// While
cout<<endl<<"Minimum net pay is: $"<<minnp<<endl;
cout<<"Maximum net pay is: $"<<maxnp<<endl;
fin.close();
} //main
|