Payrollsys

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Dexter John A.

Montemayor

The program should find the minimum and maximum net pay of all employees as well as sort the
employees based on their net pay (ascending order)

#include<fstream>
#include<iostream>
#include<iomanip>
using namespace std;
int totalEmployeeCount,hrs,employeeCounter,stat,empID;
double rate,regPay;
string fName;
string lName;

class employee{
public:
double salary,hourlyRate,taxRate,taxAmount,grossPay,netPay,otPay;
int hours,otHours;

public: void setVariables(int empID,string fName,string lName, int stat,


double rate, double hrs){
int employeeID = empID;
string firstName = fName;
string lastName = lName;
int payStat = stat;
if(payStat ==1){hourlyRate = rate;}
else{salary = rate;}
hours = hrs;
}
//DECLARE FUNCTION TO CALCULATE GROSS PAY
public: virtual double calculateGrossPay()=0;

double calculateTaxAmount(){ taxRate = .30; // tax rate is a flat rate of 30%


taxAmount = grossPay*taxRate; // CALCULATE TAX AMOUNT
return taxAmount;
} // END CALCULATE TAXAMOUNT() FUNCTION.

double calculateNetPay(){
netPay = grossPay - taxAmount;
return netPay;
} // END CALCULATENETPAY() FUNCTION.
void printData(){
cout<<setprecision(2)<<setiosflags(ios::fixed | ios::showpoint);
cout<<fName<<setw(6)<<lName<<setw(6)<<empID<<setw(10)<<hrs<<setw(3)
<<otHours<<setw(8)<<grossPay<<setw(8)<<netPay<<setw(8)<<otPay<<endl;}
// END PRINTDATA() FUNCTION
}; // END EMPLOYEE CLASS

class employeeSalary : public employee{


public: double calculateGrossPay() {
double regPay = hours*hourlyRate;
double hourlyRate = ((salary/52)/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 grossPay; }
}; //end EmployeeSalary class

class employeeHourly : public employee{


public: double calculateGrossPay(){
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

int main(){
int employeeCounter;
cout<< "enter # of employees you want to process: ";
cin>>totalEmployeeCount;
employee*employee[100];
while(employeeCounter < totalEmployeeCount){
cout<<"Is employee "<<employeeCounter+1<< " hourly or salary? (enter 1
for hourly / 2 for salary):";
cin>>stat;
if (stat == 1){cout<< "Instantiating and HOURLY employee object
inherited from base class employee"
<<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();
cout<<endl<<endl;
employeeCounter++; } //end if

else{cout<<"instantialting a SALARY employee object in herited from base class employee"


<<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();
cout<<endl<<endl;
employeeCounter++;}
}
/*employeeCounter = 0;
while (employeeCounter < totalEmployeeCount){
employee[employeeCounter]->printData();
employeeCounter++;
}*/
system("pause");
}

You might also like