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

on microsoft visual studio C++ Scenario/Summary The objective of the lab is to t

ID: 3849205 • Letter: O

Question

on microsoft visual studio C++

Scenario/Summary

The objective of the lab is to take the UML Class diagram and enhance last week's Employee class by making the following changes:

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.

STEP 1: Understand the UML Diagram

Notice the change in UML diagram. It is common practice to leave out the accessors and mutators (getters and setters) from UML class diagrams, since there can be so many of them. Unless otherwise specified, it is assumed that there is an accessor (getter) and a mutator (setter) for every class attribute.

STEP 2: Create the Project

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

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

STEP 3: Modify the Employee Class

Using the updated Employee class diagram, modify the attributes to be protected.

Delete the iEmployee interface class, and remove the reference from the Employee class.

STEP 4: Create the Salaried Class

Using the UML Diagrams from Step 1, create the Salaried classes, ensuring to specify that the Salary class inherits from the Employee class.

For each of the constructors listed in the Salaried class, ensure to invoke the appropriate base class constructor and pass the correct arguments to the base class constructor. This will initialize the protected attributes and update the numEmployees counter.

The valid management levels are 0, 1, 2, and 3, and should be implemented as a constant.

Override the calculatePay method to add a 10 percent bonus for each of the management levels (i.e., bonus percentage = managementLevel * .10). The bonus percentage should be implemented as a constant.

Override the displayEmployee() method to add the management level to the employee information.

STEP 5: Create the Hourly Class

Using the UML Diagrams from Step 1, create the Hourly classes, ensuring to specify that the Hourly class inherits from the Employee class.

For each of the constructors listed in the Hourly class, ensure to invoke the appropriate base class constructor and pass the correct arguments to the base class constructor. This will initialize the protected attributes and update the numEmployees counter.

The valid category types are "temporary", "part time", and "full time".

The provided hours must be more than 0 hours and less than 50 hours, and the limits should be implemented as constants.

The provided wage must be between 10 and 75, and the limits should be implemented as constants.

Override the calculatePay method by multiplying the wages by the number of hours.

Override the Employee setAnnualSalary method and set the annual salary by multiplying the weekly pay by 50.

Override the displayEmployee() method to add the category to the hourly employee information.

STEP 6: Modify the Main Method

Using previous weeks' assignments as an example, create at least one Employee, Hourly, and Salaried employee.

For each object created, display the number of employees created.

For each object created, write statements to exercise each of the public methods listed in the Class diagram.

For each object created, invoke the object's displayEmployee() method to display the employee's information.

For employee, the following information needs to be displayed:

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

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

STEP 7: Compile and Test

please 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 the 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 30 +Employee() +Employee (in fname string, in Iname string, in gen char, in dep int, in benefits Benefit) static getNumEmployees nt +Calculate Pay() 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

#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;
numEmployees++;
}
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;
numEmployees++;
}
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;
}

double calculatePay() //calculate weekly pay
{
return annualSalary/52;
}
void displayEmployee() // display employee information
{
cout<<" ____________________________________________";
cout<<" Name : "<<firstName<<" "<<lastName;
cout<<" Gender : "<<gender;
cout<<" Dependents : "<<dependents;
cout<<" Annual Salary : "<<annualSalary;
cout<<" Weekly Salary : "<<calculatePay();
  
cout<<" ____________________________________________";
benefit.displayBenefits();
}


};
int Employee::numEmployees = 0;

class Salaried :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(manLevel >=0 && manLevel <=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()
{
double bonus_percentage = management_Level * BONUS_PERCENT/100;
return (getAnnualSalary() + getAnnualSalary()*bonus_percentage)/52;
}
void displayEmployee()
{
cout<<" ____________________________________________";
cout<<" Name : "<<getFirstName()<<" "<<getLastName();
cout<<" Gender : "<<getGender();
cout<<" Dependents : "<<getDependents();

cout<<" Annual Salary : "<<getAnnualSalary();
cout<<" Weekly Salary : "<<calculatePay();
  
cout<<" ____________________________________________";
//benefit.displayBenefits();
cout<<" Salaried Employee";
cout<<" Management Level : "<<management_Level;
}
};

class Hourly : 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->wage = wage;
this->hours = hours;
this->category = category;
}
double calculatePay()
{
return wage*hours*50;
}
void displayEmployee()
{
cout<<" ____________________________________________";
cout<<" Name : "<<getFirstName()<<" "<<getLastName();
cout<<" Gender : "<<getGender();
cout<<" Dependents : "<<getDependents();
cout<<" Category : "<<category;
cout<<" Annual Salary : "<<calculatePay();
cout<<" Weekly Salary : "<<calculatePay()/50;
  
cout<<" ____________________________________________";
}
  
};


int main()
{
string firstname,lastname;
char gender;
int dependents,vocation;
double annualsalary,life;
string health;

cout<<setprecision(2)<<showpoint<<fixed; //set formatting
  
cout<<" Please enter your first name : ";
cin>>firstname;

cout<<" Please enter your last name : ";
cin>>lastname;

cout<<" Please enter your gender : ";
cin>>gender;

cout<<" Please enter your dependents : ";
cin>>dependents;

cout<<" Please enter your annual salary : ";
cin>>annualsalary;
  
cout<<" Please enter your health insurance : ";
cin>>health;
  
cout<<" Please enter your life insurance : ";
cin>>life;

cout<<" Please enter your vocation days : ";
cin>>vocation;
  
  
Benefit ben(health,life,vocation);

Employee emp(firstname,lastname,gender,dependents,annualsalary,ben);

emp.displayEmployee();
  
cout<<" Number of Employee objects created : "<<emp.getNumEmployees();

Benefit ben1("HMO",100,16);
Salaried emp1("Jackie","Chan",'M',1,50000.00,ben1,3);
emp1.displayEmployee();
ben1.displayBenefits();

cout<<" Number of Employee objects created : "<<emp.getNumEmployees();
Benefit ben2("PPO",5,17);
Hourly emp2("James","Bond",'M',0,40,50,ben2,"Unknown");
emp2.displayEmployee();
ben2.displayBenefits();

cout<<" Number of Employee objects created : "<<emp.getNumEmployees();
return 0;
}

Output: