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
|
#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;
void readdata();
void printreport();
void printdata();
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;
double taxRate,taxAmount,grossPay,netPay;
double calculateTaxAmount(){ taxRate = .30; //set a flat taxrate 30%
taxAmount = grossPay * taxRate; //formula to calculate tax amount
return taxAmount; } //end calculateTaxAmount() function
double calculateNetPay(){
return netPay; } //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;
regPay=grossPay;
hourlyRate=rate;
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 grossPay; }
}; //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,TotalEmployeeCounter;
double hrs,rate,Grosspay,TaxAmount,NetPay;
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 < TotalEmployeeCounter; 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 hourly wage: "; cin>>rate;
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();
}
cin.get();
system("pause");
}
}
}//end while
|