0% found this document useful (0 votes)
10 views

Case 6 (1)

Uploaded by

paulfellows91
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Case 6 (1)

Uploaded by

paulfellows91
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

#include <iostream>

#include <iomanip>

#include <vector>

#include <algorithm>

using namespace std;

class Employee {

protected:

string employeeid;

string employeename;

char maritalstatus;

int hoursworked;

double grosspay, overtimepay, taxamount, netpay;

int overtime;

public:

Employee(string id, string name, char status, int hours)

: employeeid(id), employeename(name), maritalstatus(status),


hoursworked(hours),

grosspay(0), overtimepay(0), taxamount(0), netpay(0), overtime(0) {}

virtual void calculateGrossPay() = 0;

void calculateTax() {

double taxrate;

if (grosspay >= 500)

taxrate = 0.30;

else if (grosspay > 200)


taxrate = 0.20;

else

taxrate = 0.10;

if (maritalstatus == 'S' || maritalstatus == 's')

taxrate += 0.05;

taxamount = grosspay * taxrate;

void calculateNetPay() {

netpay = grosspay - taxamount;

virtual void display() const {

cout << setprecision(2) << fixed;

cout << setw(8) << employeename << setw(8) << employeeid <<
setw(6)

<< hoursworked << setw(6) << overtime << setw(10) << grosspay

<< setw(10) << overtimepay << setw(10) << taxamount <<


setw(10)

<< netpay << endl;

double getNetPay() const {

return netpay;

}
virtual ~Employee() = default;

};

class HourlyEmployee : public Employee {

double hourlyrate;

public:

HourlyEmployee(string id, string name, char status, int hours, double rate)

: Employee(id, name, status, hours), hourlyrate(rate) {}

void calculateGrossPay() override {

if (hoursworked > 40) {

overtime = hoursworked - 40;

grosspay = (40 * hourlyrate) + (overtime * hourlyrate * 1.5);

overtimepay = overtime * hourlyrate * 1.5;

} else {

overtime = 0;

grosspay = hoursworked * hourlyrate;

overtimepay = 0;

};

class SalaryEmployee : public Employee {

double yearlysalary;
public:

SalaryEmployee(string id, string name, char status, int hours, double


salary)

: Employee(id, name, status, hours), yearlysalary(salary) {}

void calculateGrossPay() override {

grosspay = yearlysalary / 52;

if (hoursworked > 40) {

overtime = hoursworked - 40;

double hourlyrate = grosspay / 40;

overtimepay = overtime * hourlyrate * 1.5;

grosspay += overtimepay;

} else {

overtime = 0;

overtimepay = 0;

};

class Payroll {

vector<Employee*> employees;

public:

void addEmployee(Employee* emp) {

employees.push_back(emp);

}
void calculatePayroll() {

for (auto emp : employees) {

emp->calculateGrossPay();

emp->calculateTax();

emp->calculateNetPay();

void printReport() {

cout << setw(45) << "-PAYROLL REPORT-" << endl;

cout << "--------------------------------------------------------------------------------" <<


endl;

cout << "NAME ID HW OT GROSS OT-PAY TAX NETPAY"


<< endl;

cout << "--------------------------------------------------------------------------------" <<


endl;

for (auto emp : employees) {

emp->display();

void findMinAndMaxNetPay() {

auto minmax = minmax_element(employees.begin(), employees.end(),

[](Employee* a, Employee* b) { return a->getNetPay() < b-


>getNetPay(); });

cout << "Minimum Net Pay: " << setprecision(2) << fixed <<
(*minmax.first)->getNetPay() << endl;
cout << "Maximum Net Pay: " << setprecision(2) << fixed <<
(*minmax.second)->getNetPay() << endl;

void sortEmployeesByNetPay() {

sort(employees.begin(), employees.end(),

[](Employee* a, Employee* b) { return a->getNetPay() < b-


>getNetPay(); });

~Payroll() {

for (auto emp : employees) {

delete emp;

};

int main() {

Payroll payroll;

payroll.addEmployee(new HourlyEmployee("4569", "Renee", 'S', 45,


20.0));

payroll.addEmployee(new HourlyEmployee("7845", "Bob", 'M', 40, 18.5));

payroll.addEmployee(new HourlyEmployee("1004", "Paul", 'S', 38, 22.0));

payroll.addEmployee(new SalaryEmployee("8004", "Regan", 'S', 50,


52000));

payroll.addEmployee(new SalaryEmployee("6005", "Rohan", 'M', 42,


70000));
payroll.calculatePayroll();

payroll.printReport();

payroll.findMinAndMaxNetPay();

payroll.sortEmployeesByNetPay();

cout << "\n- Sorted Payroll Report by Net Pay -" << endl;

payroll.printReport();

return 0;

You might also like