Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A company pays its employees on a weekly basis. The company has three types of e

ID: 3850908 • Letter: A

Question

A company pays its employees on a weekly basis. The company has three types of employees:
• Salaried employees, who are paid a fixed weekly salary regardless of the number of hours worked;

• Hourly employees, who are paid by the hour and receive overtime pay;

• Commission based employees whose pay is based on a fixed weekly base pay of $500 plus 10% of the total sales for that week.

For example, a weekly sale of $10,000 would earn the employee a total of $1,500 ($500 base pay + $1,000 in commission) for that week.  

Create a console-based object-oriented C++ application that
• Calculates weekly pay for an employee. The application should display text that requests the user input the name of the employee, type of employee, and the weekly salary, if it's a salaried employee, or hourly rate and hours worked in the week, if it’s an hourly employee.

• For hourly employees, the rate will be doubled if it’s beyond 40 hours/week.

• The program should then print out the name of the employees, employee status, total hours worked for the week, and hourly rate if applies, and the weekly payment amounts. In the printout, display the dollar symbol ($) to the left of the weekly pay amount and format the weekly payment amount to display currency. The program should print the list in certain order, for example, by employee type, then by wage, and then by total pay.

• Implements the following features that allows the user to: o Reward selected salaried employees by adding 10% to their salaries. Your program should display an asterisk (*) to the upper right of the weekly pay amount, and a note stating bonus added below the table, as shown below:

Name                     Status             Hours             Sales            Wages            Pay

James Hogan      Salaried               -                     -                $75.00          $3,300.00*

Jennifer Waltz       Hourly                45                    -              $10.95           $547.50

Molly Smith           Hourly                32                   -              $15.00           $480.00

Bob Wagger         Commissioned     -                $20,000      $500.00        $2,500.00

Joan Han              Salaried             -                     -                $65.00          $2,860.00*

*A 10% bonus is awarded

Submission

• A design document (depicting the classes, and their relationships)
• Provide at least 5 test runs. Test runs should include at least each and every type of employee, and the report

Explanation / Answer

#include <iostream>

#include <random>

using namespace std;

class HourlyPaid {

private:

double hoursWorked;

double hourlyRate;

public:

bool setHoursWorked(double hoursWorked) {

if(hoursWorked < 0) {

return false;

}

else

this->hoursWorked = hoursWorked;

return true;

}

bool setHourlyRate(double hourlyRate) {

if(hourlyRate <= 0) return false;

this->hourlyRate = hourlyRate;

return true;

}

double getHoursWorked() {

return hoursWorked;

}

double getHourlyRate() {

return hourlyRate;

}

double calculatePay() {

if(hoursWorked > 40) {

return hoursWorked * hourlyRate + (hoursWorked - 40) * hourlyRate;

}

else

return hoursWorked * hourlyRate;

}

};

class Salaried {

private:

double salary;

public:

bool setSalary(double salary) {

if(salary <= 0) {

return false;

}

else

this->salary = salary;

return true;

}

int getSalary() {

return salary;

}

double calculatePay() {

return salary;

}

};

class Commissioned{

private:

const static int FIXED = 500;

double totalSale;

public:

bool setTotalSale(double totalSale) {

if(totalSale < 0) return false;

else

this->totalSale = totalSale;

return true;

}

double getTotalSale() {

return totalSale;

}

double calculatePay() {

return FIXED + ((10.0/100)*totalSale);

}

};

union Member {

HourlyPaid h;

Salaried s;

Commissioned c;

};

class Employee {

private:

string name;

int type;

Member m;

int bonus;

public:

Employee() {

type = -1;

bonus = 0;

}

void setName(string input) {

name = input;

}

void setType(int _type) {

type = _type;

}

void setMember(Member _m) {

m = _m;

}

string getName() {

return name;

}

int getType() {

return type;

}

Member getMember() {

return m;

}

void setBonusOn() {

bonus = 1;

}

int getBonus() {

return bonus;

}

};

int getRand() {

random_device rd;

mt19937 gen(rd());

uniform_int_distribution<> dis(0, 3);

return dis(gen);

}

void printHeader() {

cout << "Name " << "Status " << "Hours " << "Sales " << "Wages " << "Pay" << endl;

}

void quicksort(Employee *employees, int *index, int left, int right){

int min = (left+right)/2;

int i = left;

int j = right;

int temp;

while(left<j || i<right)

{

while(employees[index[i]].getName().compare(employees[index[min]].getName()) < 0)

++i;

while(employees[index[j]].getName().compare(employees[index[min]].getName()) > 0)

--j;

if(i<=j){

temp = index[i];

index[i] = index[j];

index[j] = temp;

++i;

--j;

}

else{

if(left<j)

quicksort(employees, index, left, j);

if(i<right)

quicksort(employees, index, i, right);

return;

}

}

}

void printEmployee(Employee e) {

cout << e.getName();

if(e.getName().length() < 8) {

cout << " ";

} else if(e.getName().length() < 16) {

cout << " ";

} else if(e.getName().length() < 24) {

cout << " ";

}

switch(e.getType()) {

case HOURLY:

cout << "HOURLY " << e.getMember().h.getHoursWorked() << " ";

cout << "- $" << e.getMember().h.getHourlyRate() << " ";

cout << "$" <<e.getMember().h.calculatePay();

break;

case SALARIED:

cout << "SALARIED " << "- ";

cout << "- $" << e.getMember().s.getSalary() << " ";

cout << "$";

if(e.getBonus() == 1) {

cout << (e.getMember().s.calculatePay()*1.1) << "*";

} else {

cout << e.getMember().s.calculatePay();

}

break;

case COMMISSIONED:

cout << "COMMISSIONED " << "- $";

cout << e.getMember().c.getTotalSale() << " $500 ";

cout << "$" << e.getMember().c.calculatePay();

break;

}

cout << endl;

}

void printByName(Employee *employees, int count) {

int * index = (int *) malloc(sizeof(int)*count);

int i;

for(i=0; i<count; ++i) {

index[i] = i;

}

quicksort(employees, index, 0, count-1);

for(i=0; i<count; ++i) {

printEmployee(employees[index[i]]);

}

cout << endl;

}

void printByType(Employee *employees, int count, int _type) {

int i=0;

for(i=0; i<count; ++i) {

if(employees[i].getType() ==_type) {

printEmployee(employees[i]);

}

}

cout << endl;

}

Member getSalaryInfo(int n) {

Member m;

double dn;

double pay;

if(n == HOURLY) {

cout << "Enter number of hours worked." << endl;

cin >> dn;

while (dn < 0) {

cout << "Invalid value. Try Again: " << endl;

cin >> dn;

}

m.h.setHoursWorked(dn);

cout << "Enter hourly rate (> 0)." << endl;

cin >> dn;

while (dn < 0) {

cout << "Invalid value. Try Again: " << endl;

cin >> dn;

}

m.h.setHourlyRate(dn);

pay = m.h.calculatePay();

} else if(n == SALARIED) {

cout << "Enter salary (> 0)." << endl;

cin >> dn;

while (dn < 0) {

cout << "Invalid value. Try Again: " << endl;

cin >> dn;

}

m.s.setSalary(dn);

pay = m.s.calculatePay();

} else if(n == COMMISSIONED) {

cout << "Enter total sale (> 0)." << endl;

cin >> dn;

while (dn < 0) {

cout << "Invalid value. Try Again: " << endl;

cin >> dn;

}

m.c.setTotalSale(dn);

pay = m.c.calculatePay();

}

return m;

}

int main() {

char choice = 'y';

int count = 0;

string input;

string temp;

Employee employees[MAX];

while(choice == 'y') {

cout << "Enter 'y' to enter Employee, 'n' to print existing database and exit: ";

cin >> choice;

getline(cin, temp);

while((choice != 'y') && (choice != 'n')) {

cout << "Invalid Choice. Try Again: ";

cin >> choice;

getline(cin, temp);

}

if(choice == 'y') {

cout << "Enter name of Employee: ";

getline(cin, input);

employees[count].setName(input);

cout << "Enter 1 if it is hourly employee. ";

cout << "Enter 2 if it is salaried employee. ";

cout << "Enter 3 if it is commissioned employee. ";

cin >> choice;

while(choice < HOURLY || choice > COMMISSIONED ) {

cout << "Invalid Choice. Try Again: ";

cin >> choice;

}

employees[count].setType(choice);

employees[count].setMember(getSalaryInfo(choice));

if(choice == SALARIED) {

cout << "Enter 'y' to provide bonus to this salaried employee, 'n' to skip: ";

cin >> choice;

while(choice != 'y' && choice != 'n') {

cout <<"Invalid input. Please try again: ";

cin >> choice;

}

if(choice == 'y') {

cout <<"Thank you for giving bonus to emloyee. ";

employees[count].setBonusOn();

} else cout <<"No bonus for this employee. ";

}

if(choice == SALARIED && getRand() == 1) {

employees[count].setBonusOn();

}

choice = 'y';

++count;

} else if(choice == 'n') {

if(count == 0 ) {

cout << "No Employee" << endl;

return 0;

}

cout <<" ---------------Emloyee database sorted by name only------------ ";

printHeader();

printByName(employees, count);

cout <<" ---------------Emloyee database sorted by Type only------------ ";

printHeader();

printByType(employees, count, HOURLY);

printByType(employees, count, SALARIED);

printByType(employees, count, COMMISSIONED);

cout << "*A 10% bonus is awarded ";

}

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote