on microsoft studio C++ We have two separate goals this week: We are going to cr
ID: 3868095 • 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.
week 5 https://www.chegg.com/homework-help/questions-and-answers/c-microsoft-visual-scenario-summary-objective-lab-take-uml-class-diagram-enhance-last-week-q23430827
Benefit healthinsurance : string -lifeinsurance: double -vacation int +Benefit +Benefit(in hins: string, in lins: double, in vac: int ) -displayBenefits void K Employee #firstName: string #lastName string #gender: char #dependents : int #annualSalary : double #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() : int +CalculatePay(): double -displayEmployee) void Salaried -MIN MANAGEMENT LEVEL :int = 0 -MAX _MANAGEMENT LEVEL:int = 3 -BONUS PERCENT : double = 10 -managementLevel: int +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: int ) +CalculatePayC) : double +displayEmployee() void Hourl -MIN WAGE : double = 10 -MAX_WAGE : double = 75 -MIN HOURS : double = 0 MAX HOURS: double = 50 -wage : double -hours: double -category: string +Hourly ) +Hourlyin wage : double, in hours : double, in category: string) +Hourly in fname: string, in Iname string, in gen: char, in dep: int, in vage: double, in hours: double, in ben: Benefit, in category: string +CalculatePa' ) : double -displayEmployee voidExplanation / Answer
#include <iostream>
#include <iomanip>
#include <cstring>
using namespace std;
class Benefit
{
private:
string healthInsurance;
double lifeInsurance;
int vacation;
public:
Benefit()
{
healthInsurance = " ";
lifeInsurance = 0.0;
vacation = 0;
}
Benefit(string hins,double lins,int vac)
{
healthInsurance = hins;
lifeInsurance = lins;
vacation = vac;
}
void displayBenefits()
{
cout<<" Benefit Information";
cout<<" _______________________________________________________________";
cout<<" Health Insurance "<<healthInsurance;
cout<<" Life Insurance "<<lifeInsurance;
cout<<" Vacation"<<vacation;
}
};
class Employee
{
//variables
private:
string firstName;
string lastName;
char gender;
int dependents;
double annualSalary;
Benefit benefit;
static int numEmployees ;
public:
Employee() //default constructor
{
firstName = "not given";
lastName = "not given";
gender = 'U' ;
dependents = 0;
annualSalary = 20000;
}
Employee(string firstName,string lastName,char gender,int dependents,double annualSalary,Benefit benefit)//parameterized constructor
{
this->firstName = firstName;
this->lastName = lastName;
this->gender = gender;
this->dependents = dependents;
this->annualSalary = annualSalary;
this->benefit = benefit;
}
static int getNumEmployees()
{
return numEmployees;
}
//set and get methods
void setFirstName(string firstName)
{
this->firstName = firstName;
}
void setLastName(string lastName)
{
this->lastName = lastName;
}
void setGender(char gender)
{
this->gender = gender;
}
void setDependents(int dependents)
{
this->dependents = dependents;
}
void setAnnualSalary(double annualSalary)
{
this->annualSalary = annualSalary;
}
string getFirstName()
{
return firstName;
}
string getLastName()
{
return lastName;
}
char getGender()
{
return gender;
}
int getDependents()
{
return dependents;
}
double getAnnualSalary()
{
return annualSalary;
}
virtual double calculatePay()=0; //calculate weekly pay
virtual void displayEmployee() = 0; // display employee information
};
class Salaried :public Employee
{
private:
int MIN_MANAGEMENT_LEVEL = 0;
int MAX_MANAGEMENT_LEVEL = 3;
double BONUS_PERCENT = 10;
int management_Level;
public:
Salaried()
{
management_Level = 0;
}
Salaried(string fname,string lname,char gen,int dep,double sal,Benefit ben,int manLevel):Employee(fname,lname,gen,dep,sal,ben)
{
if(management_Level >=0 && management_Level <=3)
management_Level = manLevel;
else
management_Level = 0;
}
Salaried(double sal,int manLevel)
{
if(management_Level >=0 && management_Level <=3)
management_Level = manLevel;
else
management_Level = 0;
}
double calculatePay()
{
return getAnnualSalary()/52;
}
void displayEmployee()
{
cout<<" ____________________________________________";
cout<<" Name : "<<getFirstName()<<" "<<getLastName();
cout<<" Gender : "<<getGender();
cout<<" Dependents : "<<getDependents();
cout<<" Annual Salary : "<<getAnnualSalary();
cout<<" Weekly Salary : "<<calculatePay();
cout<<" ____________________________________________";
}
};
class Hourly : public Employee
{
private:
double MIN_WAGE = 10;
double MAX_WAGE = 75;
double MIN_HOURS = 0;
double MAX_HOURS = 50;
double wage;
double hours;
string category;
public:
Hourly()
{
}
Hourly(double wage,double hours,string category)
{
this->wage = wage;
this->hours = hours;
this->category = category;
}
Hourly(string fname,string lname,char gen,int dep,double wage,double hours,Benefit ben,string category):Employee(fname,lname,gen,dep,this->wage*this->hours,ben)
{
this->category = category;
}
double calculatePay()
{
return wage*hours;
}
void displayEmployee()
{
cout<<" ____________________________________________";
cout<<" Name : "<<getFirstName()<<" "<<getLastName();
cout<<" Gender : "<<getGender();
cout<<" Dependents : "<<getDependents();
cout<<" Annual Salary : "<<getAnnualSalary();
cout<<" Weekly Salary : "<<calculatePay();
cout<<" ____________________________________________";
}
};
int main()
{
string firstname,lastname;
int dependents;
double annualSalary;
char gender;
Benefit benSal("PPO",1.5,21);
Benefit benHour("HMO",100,18);
Employee *employeeList1 = new Salaried(10000,3);
Employee *employeeList2 = new Hourly(50,40,"full time");
cout<<setprecision(2)<<showpoint<<fixed; //set formatting
cout<<" Please enter your first name : ";
cin>>firstname;
employeeList1->setFirstName(firstname);
cout<<" Please enter your last name : ";
cin>>lastname;
employeeList1->setLastName(lastname);
cout<<" Please enter your gender : ";
cin>>gender;
employeeList1->setGender(gender);
cout<<" Please enter your dependents : ";
cin>>dependents;
employeeList1->setDependents(dependents);
cout<<" Please enter your annual salary : ";
cin>>annualSalary;
employeeList1->setAnnualSalary(annualSalary);
employeeList1->displayEmployee();
benSal.displayBenefits();
cout<<" Please enter your first name : ";
cin>>firstname;
employeeList2->setFirstName(firstname);
cout<<" Please enter your last name : ";
cin>>lastname;
employeeList2->setLastName(lastname);
cout<<" Please enter your gender : ";
cin>>gender;
employeeList2->setGender(gender);
cout<<" Please enter your dependents : ";
cin>>dependents;
employeeList2->setDependents(dependents);
cout<<" Please enter your annual salary : ";
cin>>annualSalary;
employeeList2->setAnnualSalary(annualSalary);
employeeList2->displayEmployee();
benHour.displayBenefits();
return 0;
}
output:
Please enter your first name : Nana
Please enter your last name : Liu
Please enter your gender : F
Please enter your dependents : 2
Please enter your annual salary : 60000
____________________________________________
Name : Nana Liu
Gender : F
Dependents : 2
Annual Salary : 60000.00
Weekly Salary : 1153.85
____________________________________________
Benefit Information
_______________________________________________________________
Health Insurance PPO
Life Insurance 1.50
Vacation21
____________________________________________
Please enter your first name : jackie
Please enter your last name : Chan
Please enter your gender : M
Please enter your dependents : 1
Please enter your annual salary : 100000
____________________________________________
Name : jackie Chan
Gender : M
Dependents : 1
Annual Salary : 100000.00
Weekly Salary : 2000.00
____________________________________________
Benefit Information
_______________________________________________________________
Health Insurance HMO
Life Insurance 100.00
Vacation18
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.