Question: Create a class called Salaried that is derived from Employee. Create a class called Hourly that is also derived from Employee. Override the base class

Create a class called Salaried that is derived from Employee.

Create a class called Hourly that is also derived from Employee.

Override the base class calculatePay() method.

Override the displayEmployee() method.

###########Benefit.h##########

#include

#include

using namespace std;

class Benefit {

public:

Benefit();

Benefit(string, double, int);

void displayBenefits();

string getHealthInsurance();

void setHealthInsurance(string);

double getLifeInsurance();

void setLifeInsurance(double);

int getVacation();

void setVacation(int);

private:

string healthInsurance;

double lifeInsurance;

int vacation;

};

##############Employee.h##################

#include

#include

using namespace std;

class Employee {

public:

Employee();

Employee(string, string, char, int, double);

void displayEmployee();

string getFirstName();

void setFirstName(string);

string getLastName();

void setLastName(string);

char getGender();

void setGender(char);

int getDependents();

void setDependents(int);

double getAnnualSalary();

void setAnnualSalary(double);

void setAnnualSalary(string);

static int getNumEmployees();

void setDependents(string);

private:

string firstName;

string lastName;

char gender;

int dependents;

double annualSalary;

static int numEmployee;

virtual double calculatePay();

};

#######################Employee.cpp#########

#include

#include

#include "Employee.h"

#include "Benefits.h"

using namespace std;

int Employee::numEmployee=0;

Employee::Employee() {

firstName = "not given";

lastName = "not given";

gender = 'U';

dependents = 0;

annualSalary = 20000;

numEmployee++;

}

Employee::Employee(string first, string last, char gen, int dep,

double salary) {

firstName = first;

lastName = last;

gender = gen;

dependents = dep;

annualSalary = salary;

numEmployee++;

}

Benefit::Benefit() {

healthInsurance=" not given";

lifeInsurance=0;

vacation=0;

}

Benefit::Benefit(string hInsurance, double lInsurance, int vacationDays){

healthInsurance=hInsurance;

lifeInsurance=lInsurance;

vacation=vacationDays;

}

string Benefits::Benefit::getHealthInsurance() {

return healthInsurance;

}

double Benefits::Benefit::getLifeInsurance() {

return lifeInsurance;

}

int Benefits::Benefit::getVacation() {

return vacation;

}

void Benefits::Benefit::setHealthInsurance(string hInsurance){

healthInsurance=hInsurance;

}

void Benefits::Benefit::setLifeInsurance(double lInsurance) {

lifeInsurance=lInsurance;

}

void Benefits::Benefit::setVacation(int vacationDays) {

vacation=vacationDays;

}

string Employee::getFirstName() {

return firstName;

}

string Employee::getLastName() {

return lastName;

}

void Employee::setFirstName(string fname) {

firstName = fname;

}

void Employee::setLastName(string lname) {

lastName = lname;

}

char Employee::getGender() {

return gender;

}

void Employee::setGender(char gen) {

switch (gen) {

case 'f':

case 'F':

case 'M':

case 'm':

gender = gen;

break;

default:

gender = 'U';

}

}

void Employee::setDependents(int dep) {

dependents = dep;

}

double Employee::getAnnualSalary() {

return annualSalary;

}

void Employee::setAnnualSalary(double salary) {

annualSalary = salary;

}

double Employee::calculatePay() {

return (annualSalary / 52);

}

int Employee::getNumEmployees()

{

return numEmployee;

}

void Employee::displayEmployee() {

cout << "Employee Information" << endl;

cout

<< "----------------------------------------------------------------------------"

<< endl;

cout << setw(16) << left << "Name:" << firstName << " " << lastName << endl;

cout << setw(16) << "Gender:" << gender << endl;

cout << setw(16) << "Dependents:" << dependents << endl;

cout << setw(16) << fixed << setprecision(2) << "Annual Salary:"

<< annualSalary << endl;

cout << setw(16) << "Weekly Salary:" << calculatePay() << endl;

}

void Benefits::Benefit::displayBenefits() {

cout<< "Employee Benefits Information"<

cout

<< "----------------------------------------------------------------------------"

<< endl;

cout << setw(16) << left << "Health Insurance:" << healthInsurance<< endl;

cout << setw(16) << "Life Insurance:" << lifeInsurance << endl;

cout << setw(16) << fixed << setprecision(2) << "Vacation:"

<< vacation << endl;

}

#############EmployeeTest##############

#include "Employee.cpp"

#include

#include

#include

#include

using namespace std;

int main() {

cout<< "Welcome to your first Object Oriented Program==Employee ClassCIS247C, Week 1 Lab"<< endl;

cout << "Name: Alejandra Dominguez-Cuevas" << endl;

cout << "************** Employee 1 **************" << endl;

Employee emp;

string first;

string last;

string gen;

string dependents;

string salary;

string healthInsurance;

double lifeInsurance;

int vacation;

cout << "Please enter your First name ";

cin >> first;

cout << "Please enter your Last name ";

cin >> last;

cout << "Please enter your Gender ";

cin >> gen;

cout << "Please enter your Dependents ";

cin >> dependents;

cout << "Please enter your Annual Salary ";

cin >> salary;

cout << "Please enter your Health Insurance";

cin >> healthInsurance;

cout << "Please enter your Life Insurance";

cin >> lifeInsurance;

cout << "Please enter your Vacation Days";

cin >> vacation;

emp.setFirstName(first);

emp.setLastName(last);

emp.setDependents(atoi(dependents.c_str()));

emp.setAnnualSalary(atof(salary.c_str()));

emp.benefit.setHealthInsurance(healthInsurance);

emp.benefit.setLifeInsurance(lifeInsurance);

emp.benefit.setVacation(vacation);

if (gen == "Female") {

emp.setGender('F');

} else if (gen == "Male") {

emp.setGender('M');

} else {

emp.setGender('U');

}

emp.displayEmployee();

cout << "************** Employee 2 **************" << endl;

Employee emp2("Mary", "Noia", 'F', 5, 24000.0);

emp2.displayEmployee();

emp2.setFirstName(first);

emp2.setLastName(last);

emp2.setDependents(atoi(dependents.c_str()));

emp2.setAnnualSalary(atof(salary.c_str()));

emp2.benefit.setHealthInsurance(healthInsurance);

emp2.benefit.setLifeInsurance(lifeInsurance);

emp2.benefit.setVacation(vacation);

if (gen == "Female") {

emp2.setGender('F');

} else if (gen == "Male") {

emp2.setGender('M');

} else {

emp2.setGender('U');

}

emp2.displayEmployee();

emp2.benefit.displayBenefits();

cout << "The end of the CIS247C Week4 iLab" << endl;

system("pause");

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!