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
|
#include<fstream>
#include <iostream>
#include<iomanip>
using namespace std;
class payroll{
public: void setVariables(int empID, string fName, string lName, int stat, double rate, double hrs){
int employeeID;
string firstName;
string lastName;
int payStat;
double hourlyRate,salary,hours,grosspay;
void readdata();
void printreport();
void printdata();
void calculategrossPay();
employeeID = empID; firstName = fName; lastName = lName; payStat = stat;
if (payStat == 1){ hourlyRate = rate; }
else { salary = rate;}
hours = hrs; }
//declare function to calculate gross pay
public: virtual double calculateGrossPay() = 0;
int hrs;
double taxRate,taxAmount,grossPay,netPay,hourlyRate;
double calculateTaxAmount(){ taxRate = .30; //set a flat taxrate 30%
grossPay=hourlyRate*hrs;
taxAmount = grossPay * taxRate; //formula to calculate tax amount
return taxAmount; } //end calculateTaxAmount() function
double calculateNetPay(){
return grossPay;
return netPay;
return taxAmount; } //end
void printheadings();
void printData(){ //print out the data
}//end printData() function
}; //end Payroll class
class employeeSalary : public payroll{
public: double calculateGrossPay() {
double regPay,hourlyRate,rate,hours,otHours,otPay,yearlysalary,salarygrosspay;
regPay=salarygrosspay;
hourlyRate=rate;
salarygrosspay=yearlysalary/52;
hourlyRate=salarygrosspay/40;
if (hours > 40) {otHours = (hours - 40); //calculate OT hours
otPay = (otHours * hourlyRate); //calculate OT pay
grossPay = (regPay + otPay); }
else if (hours <= 40) {otHours = 0; otPay = 0; grossPay = regPay;}
return salarygrosspay;
return otPay; }
}; //end EmployeeSalary class
class employeeHourly : public payroll{
public: double calculateGrossPay(){
double regPay,hourlyRate,otHours,hours,otPay;
regPay = (40 * hourlyRate); //calculate regular hours
if (hours > 40){ otHours = (hours - 40); //calculate OT hours
otPay = (otHours * hourlyRate * 1.5); //calculate OT pay
grossPay = (regPay + otPay); //calculate gross pay
} //enf if clause for gross pay with overtime
else { otHours = 0; otPay = 0; grossPay = regPay;
} //end else clause for four hours
return grossPay; } //end calculateGrossPay() function
}; //end EmployeeHourly class
void printHeader(){
}//end printHeader() function
int main(void){
int EmployeeCount,TotalEmployeeCount,EmployeeCounter,stat,empID;
double hrs,rate,Grosspay,TaxAmount,NetPay,yearlysalary;
string fName,lName;
EmployeeCounter=0;
cout<<"Enter # of employees you want to process: ";
cin>>TotalEmployeeCount;
payroll *employee[100];
//while loop to get input for each employee
cerr<<"EmployeeCounter= "<<EmployeeCounter<<endl;
cerr<<"TotalEmployeeCount= "<<TotalEmployeeCount<<endl;
for(EmployeeCounter = 0; EmployeeCounter < TotalEmployeeCount; EmployeeCounter++)
{
//prompt the user for hourly or salary employee
cout<<"Is employee "<<EmployeeCounter+1<<" hourly or salary? (Enter 1 for HOURLY / 2 for SALARY): ";
cin>>stat;
if (stat == 1){cout<<"Instantiating an HOURLY employee object inherited from base class payroll..."<<endl<<endl;
cout<<"Enter employee's ID: ";cin>>empID;
cout<<"Enter employee's first name: ";cin>>fName;
cout<<"Enter employee's last name: ";cin>>lName;
cout<<"Enter employee's hourly wage: "; cin>>rate;
cout<<"Enter employee's hours for this week: "; cin>>hrs;
employee[EmployeeCounter] = new employeeHourly();
employee[EmployeeCounter]->setVariables(empID, fName, lName, stat, rate, hrs);
employee[EmployeeCounter]->calculateGrossPay();
employee[EmployeeCounter]->calculateTaxAmount();
employee[EmployeeCounter]->calculateNetPay();
} //end if
else{
cout<<"Instantiating a SALARY employee object inherited from base class payroll..."<<endl<<endl;
cout<<"Enter employee's ID: ";cin>>empID;
cout<<"Enter employee's first name: ";cin>>fName;
cout<<"Enter employee's last name: ";cin>>lName;
cout<<"Enter employee's yearly salary: "; cin>>yearlysalary;
cout<<"Enter employee's hours for this week: "; cin>>hrs;
employee[EmployeeCounter]=new employeeSalary();
employee[EmployeeCounter]->setVariables(empID,fName,lName,stat,rate,hrs);
employee[EmployeeCounter]->calculateGrossPay();
employee[EmployeeCounter]->calculateTaxAmount();
employee[EmployeeCounter]->calculateNetPay();
}
int employeeCounter=0;
employee[employeeCounter];
employee[employeeCounter];
string fName,lName;
int stat;
double hrs,rate,grossPay;
while(cin>>empID>>fName>>lName>>hrs>>rate){
if(stat==1){
employee[employeeCounter]=new employeeHourly();
employee[employeeCounter]->setVariables(empID,fName,lName,stat,hrs,rate);
employee[employeeCounter]->virtual double grossPay(); }//if h
if(stat==2){
employee[employeeCounter]=new employeeSalary();
employee[employeeCounter]->setVariables(int empID,string fName,string lName,double yearlysalary,double hrs);
employee[employeeCounter]->findgrosspay(); }//if s
n++;
}//WHILE
sortnetpays(netpay,n);
cin.get();
system ("pause");
}//MAIN
system("pause");
|