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

on microsoft studio C++ We have two separate goals this week: We are going to cr

ID: 3847531 • Letter: O

Question

on microsoft studio C++

We have two separate goals this week:

We are going to create an abstract Employee class and two pure virtual functions - calculatePay() and displayEmployee(). The abstract Employee class will prevent a programmer from creating an object based on Employee, however, a pointer can still be created. Objects based on Salaried and Hourly will be allowed. The pure virtual function calculatePay() in Employee will force the child classes to implement calculatePay(). The other pure virtual function displayEmployee() in Employee will force the child classes to implement displayEmployee().

We are going to implement Polymorphism and dynamic binding in this iLab.

Notice in the updated UML diagram that the Employee class is designated as abstract by having the class name Employee italicized. Also, the calculatePay method is italicized, which means that it is a pure virtual function and needs to be implemented in the derived classes. In addition, make displayEmployee() method a pure virtual function as well.

Listen

STEP 2: Create the Project

Create a new project and name it CIS247C_WK6_Lab_LASTNAME. Copy all the source files from the Week 5 project into the Week 6 project.

Before you move on to the next step, build and execute the Week 6 project.

Listen

STEP 3: Modify the Employee Class

Define calculatePay() as a pure virtual function.

Define displayEmployee() as a pure virtual function.

When class Employee contains two pure virtual functions, it becomes an abstract class.

Listen

STEP 4: Create Generalized Input Methods

Reuse method getInput() from the previous iLab to prompt the user to enter Employee information.

Listen

STEP 5: Modify the Main Method

Create two employee pointers with:

The first employee pointer refers to a salaried employee and the second employee pointer refers to a hourly employee.

Prompt the user to enter information for these two pointers and display the calculated result.

For salaried employee, the following information needs to be displayed:

For hourly employee, the following information needs to be displayed:

Listen

STEP 6: Compile and Test

When done, compile and run your code.

Then, debug any errors until your code is error-free.

Check your output to ensure that you have the desired output, modify your code as necessary, and rebuild.

Below is a complete sample program output for your reference.

Benefit Employee healthinsurance string #firstName string -lifeinsurance double #lastName string vacation int #gender char +Benefit #dependents int +Benefit (in hins String, in lins double, in vac: nt #annual salary double display Benefits Void #benefit Benefit static numEmployees int 0 +Employee() +Employee(in fname string, in Iname string, in gen char, in dep int, in benefits Benefit static getNumEmployees nt +CalculatePa double display Employee Void Salaried MIN MANAGEMENT LEVEL int 0 MAX MANAGEMENT LEVEL int 3 BONUS PERCENT double 10 management eve nt +Salaried +Salaried(in fname string, in Iname string, in gen char, in dep int, in sal double, in ben Benefit, in manLevel int) +Salaried in sal double, in manLevel nt +CalculatePay() double +displayEmployee() void Hour MIN WAGE double 10 MAX WAGE double 75 MIN HOURS double 0 -MAX HOURS: double 50 -wage double -hours double category: string +Hour +Hourly(in w double, in hours double, in category: string age +Hourly n fname string, in Iname string, in gen char, in dep int, in age double n hours double, in ben Benefit, in category: string +Calculate Pay() double display Employee Void

Explanation / Answer

Answer:

Note: User given variable names and method names are used.

#include <iostream>

#include <string>

#include <cstdlib>

#include <iomanip>

using namespace std;

class Benefit

{

string healthInsurance;

double lifeInsurance;

int vacation;

public:

Benefit()

{

healthInsurance="";

lifeInsurance=0;

vacation=0;

}

Benefit(string in_hns, double in_ins, int in_vac)

{

healthInsurance=in_hns;

lifeInsurance=in_ins;

vacation=in_vac;

}

void displayBenefits()

{

cout<<"Benefit Information"<<endl;

cout<<"------------------------------------------"<<endl;

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

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

cout<<setw(30)<<left<<"Vacation:"<<vacation<<" days"<<endl;

}

};

class Employee

{

private:

static int numEmployees;

protected:

string firstName;

string lastName;

char gender;

int dependents;

double annualSalary;

Benefit benefit;

public:

Employee()

{

this->numEmployees += 1;

firstName="";

lastName="";

gender='F';

dependents=0;

annualSalary=0;

//benefit=new Benefit();

}

Employee(string fname, string lname, char gen, int in_dep, Benefit benefits):benefit(benefits)

{

this->numEmployees += 1;

firstName=fname;

lastName=lname;

gender=gen;

dependents=in_dep;

}

static int getNumEmployees()

{

return numEmployees;

}

virtual double calculatePay()=0;

virtual void displayEmployee()=0;

};

int Employee::numEmployees=0;

class Salaried:public Employee

{

const int MIN_MANAGEMENT_LEVEL=0;

const int MAX_MANAGEMENT_LEVEL=3;

const double BONUS_PERCENT=10;

int managementLevel;

public:

Salaried():Employee()

{

//MIN_MANAGEMENT_LEVEL=0;

//MAX_MANAGEMENT_LEVEL=3;

//BONUS_PERCENT=10;

annualSalary=0;

managementLevel=0;

}

Salaried(string fname, string lname, char gen, int in_dep,double in_sal, Benefit benefits,int manLevel):Employee(fname, lname, gen, in_dep,benefits)

{

//MIN_MANAGEMENT_LEVEL=0;

//MAX_MANAGEMENT_LEVEL=3;

//BONUS_PERCENT=10;

annualSalary=in_sal;

if(manLevel>=MIN_MANAGEMENT_LEVEL && manLevel<=MAX_MANAGEMENT_LEVEL)

managementLevel=manLevel;

else

managementLevel=0;

}

Salaried(double in_sal, int manLevel):Employee()

{

annualSalary=in_sal;

if(manLevel>=MIN_MANAGEMENT_LEVEL && manLevel<=MAX_MANAGEMENT_LEVEL)

managementLevel=manLevel;

else

managementLevel=0;

}

double calculatePay()

{

return annualSalary/40;

}

void displayEmployee()

{

cout<<"Employee Information"<<endl;

cout<<"----------------------------------------------"<<endl;

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

cout<<setw(20)<<left<<"Gender:"<<gender<<endl;

cout<<setw(20)<<left<<"Dependents:"<<dependents<<endl;

cout<<setw(20)<<left<<"Annual Salary:"<<annualSalary<<endl;

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

cout<<endl;

benefit.displayBenefits();

cout<<"Salaried Employee"<<endl;

cout<<setw(20)<<left<<"Manangement level:"<<managementLevel<<endl;

}

};

class Hourly:public Employee

{

const double MIN_WAGE=10;

const double MAX_WAGE=75;

const int MIN_HOURS=0;

const int MAX_HOURS=50;

double wage;

double hours;

string category;

public:

Hourly():Employee()

{

wage=0;

hours=0;

category="";

}

Hourly(double in_wage, double in_hours, string in_category):Employee()

{

if(in_wage>=MIN_WAGE && in_wage<=MAX_WAGE)

wage=in_wage;

else

wage=0;

if(in_hours>=MIN_HOURS && in_hours<=MAX_HOURS)

hours=in_hours;

else

hours=0;

category=in_category;

}

Hourly(string fname, string lname, char gen, int in_dep,double in_wage, double in_hours, Benefit in_ben, string in_category):Employee(fname,lname, gen, in_dep, in_ben)

{

if(in_wage>=MIN_WAGE && in_wage<=MAX_WAGE)

wage=in_wage;

else

wage=0;

if(in_hours>=MIN_HOURS && in_hours<=MAX_HOURS)

hours=in_hours;

else

hours=0;

category=in_category;

}

double calculatePay()

{

return wage*hours;

}

void displayEmployee()

{

cout<<"Employee Information"<<endl;

cout<<"----------------------------------------------"<<endl;

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

cout<<setw(20)<<left<<left<<"Gender:"<<gender<<endl;

cout<<setw(20)<<left<<"Dependents:"<<dependents<<endl;

cout<<setw(20)<<left<<"Annual Salary:"<<annualSalary<<endl;

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

cout<<endl;

benefit.displayBenefits();

cout<<"Hourly Employee"<<endl;

cout<<setw(30)<<left<<"category:"<<category<<endl;

cout<<setw(30)<<left<<"Wage:"<<wage<<endl;

cout<<setw(30)<<left<<"Hours:"<<hours<<endl;

}

};

int main()

{

string lname, fname, category;

double sal=0;

string gender;

char gen='F';

int dep;

string heal;

double life;

int vacation;

cout<<"Welcome to your Object Oriented Program-";

cout<<" ";

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

cout<<"Please enter your First Name:"<<endl;

cin>>fname;

cout<<"Please enter your Last Name:";

cin>>lname;

cout<<"Please enter your Gender:";

cin>>gender;

if(gender.compare("Male")==0)

gen='M';

cout<<"Please enter your dependents:";

cin>>dep;

cout<<"Please enter your Annual Salary:";

cin>>sal;

cout<<"Please enter your Health Insurance:";

cin>>heal;

cout<<"Please enter your life Insurance:";

cin>>life;

cout<<"Please enter your Vocation:";

cin>>vacation;

Benefit bb(heal, life, vacation);

Employee *emp=new Salaried(fname, lname, gen, dep, sal, bb, 3);

emp->displayEmployee();

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

cout<<"Please enter your First Name:"<<endl;

cin>>fname;

cout<<"Please enter your Last Name:";

cin>>lname;

cout<<"Please enter your Gender:";

cin>>gender;

if(gender.compare("Male")==0)

gen='M';

cout<<"Please enter your dependents:";

cin>>dep;

cout<<"Please enter your Health Insurance:";

cin>>heal;

cout<<"Please enter your life Insurance:";

cin>>life;

cout<<"Please enter your Vocation:";

cin>>vacation;

Benefit bb2(heal, life, vacation);

Employee *emp1=new Hourly(fname, lname, gen, dep, 50,40, bb2, "full time");

emp1->displayEmployee();

cout<<"Number of employees created:"<<Employee::getNumEmployees()<<endl;

return 0;

}

Sample Output:

Welcome to your Object Oriented Program-

***********Employee 1 *************

Please enter your First Name:

Nama

Please enter your Last Name:Liu

Please enter your Gender:Female

Please enter your dependents:2

Please enter your Annual Salary:60000

Please enter your Health Insurance:HPO

Please enter your life Insurance:1.5

Please enter your Vocation:21

Employee Information

----------------------------------------------

Name:               Nama Liu

Gender:             F

Dependents:         2

Annual Salary:      60000

Weekly Salary:      1500

Benefit Information

------------------------------------------

Health Insurance:             HPO

Life Insurance:               1.5

Vacation:                     21 days

Salaried Employee

Manangement level: 3

***********Employee 2 *************

Please enter your First Name:

Jackie

Please enter your Last Name:Chan

Please enter your Gender:Male

Please enter your dependents:1

Please enter your Health Insurance:MPO

Please enter your life Insurance:100.00

Please enter your Vocation:18

Employee Information

----------------------------------------------

Name:               Jackie Chan

Gender:             M

Dependents:         1

Annual Salary:      0

Weekly Salary:      2000

Benefit Information

------------------------------------------

Health Insurance:             MPO

Life Insurance:               100

Vacation:                     18 days

Hourly Employee

category:                     full time

Wage:                         50

Hours:                        40

Number of employees created:2