on C++ microsoft visual. Scenario/Summary The objective of the lab is to take th
ID: 3866841 • Letter: O
Question
on C++ microsoft visual.
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.
Software Citation Requirements
This course uses open-source software, which must be cited when used for any student work. Citation requirements are on the Open Source Applications page.
Please review the installation instruction files to complete your assignment.
Deliverables
Due this week:
Capture the Console output window and paste into a Word document.
Zip the project folder file.
Upload the zip file and screenshots (Word document).
Required Software
Connect to the Lab here. (Links to an external site.)Links to an external site.
Lab Steps
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
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.
Explanation / Answer
Below is your program..
#include<iostream>
#include<iomanip>
#include<stdlib.h>
#include<sstream>
using namespace std;
class Benefit {
private:
string healthinsurance;
double lifeinsurance;
int vacation;
public:
Benefit() {
healthinsurance = "";
lifeinsurance = 0;
vacation = 0;
}
Benefit(string health, double life, int vaca) {
healthinsurance = health;
lifeinsurance = life;
vacation = vaca;
}
//method that displays employee information
void displayBenefits()
{
cout << " Benefit Information ";
cout << "________________________________________________________________ ";
cout << " Health Insurance: " << healthinsurance;
cout << " Life Insurance: " << fixed << setprecision(2) << lifeinsurance;
cout << " Vacation: " << vacation << " days";
}
void setHealthInsurance(string hins) {
healthinsurance = hins;
}
string getHealthInsurance() {
return healthinsurance;
}
void setLifeInsurance(double lifeins) {
lifeinsurance = lifeins;
}
double getLifeInsurance() {
return lifeinsurance;
}
void setVacation(int vaca) {
vacation = vaca;
}
int getVacation() {
return vacation;
}
};
class Employee
{
private:
static int numEmployees;
//member variables of Employee class
protected:
string firstName;
string lastName;
char gender;
int dependents;
double annualSalary;
Benefit benefit;
public:
//default constructor
Employee()
{
//set the member variables to default values
firstName = "not given";
lastName = "not given";
gender = 'U';
dependents = 0;
annualSalary = 20000;
//Incrementing number of employees
numEmployees += 1;
}
//constructor with parameters
Employee(string first, string last, char gen, int dep, double salary, Benefit benef)
{
//set the member variables to values passed
firstName = first;
lastName = last;
gender = gen;
dependents = dep;
annualSalary = salary;
//Incrementing number of employees
numEmployees += 1;
benefit = benef;
}
//getter methods
//method that gets firstName
string getfirstName()
{
return firstName;
}
//method that gets lastName
string getlastName()
{
return lastName;
}
//method that gets gender
char getGender()
{
return gender;
}
//method that gets dependents
int getdependents()
{
return dependents;
}
//method that gets annual salary
double getannualSalary()
{
return annualSalary;
}
//setter methods
//method that sets firstname
void setfirstName(string first)
{
firstName = first;
}
//method that sets lastname
void setlastName(string last)
{
lastName = last;
}
//method that sets gender
void setGender(char gen)
{
gender = gen;
}
//method that sets dependents
void setdependents(int dep)
{
dependents = dep;
}
//method that sets annual salary
void setannualSalary(double salary)
{
annualSalary = salary;
}
//Overloaded method that sets dependents
void setdependents(string dep)
{
dependents = stoi(dep);
}
//Overloaded method that sets annual salary
void setannualSalary(string salary)
{
annualSalary = stod(salary);
}
//method that calculates weekly pay
double calculatePay()
{
//calculate and return weekly pay
return annualSalary / 52;
}
//Static method
static int getNumEmployees()
{
//Return number of employee objects created
return numEmployees;
}
Benefit getBenefit() {
return benefit;
}
void setBenefit(Benefit ben) {
benefit = ben;
}
//method that displays employee information
void displayEmployee()
{
cout << " Employee Information ";
cout << "________________________________________________________________ ";
cout << " Name: " << firstName << " " << lastName;
cout << " Gender: " << gender;
cout << " Dependents: " << dependents;
cout << " Annual Salary: " << fixed << setprecision(2) << annualSalary;
cout << " Weekly Salary: " << fixed << setprecision(2) << calculatePay();
cout << " ";
benefit.displayBenefits();
}
};
int Employee::numEmployees = 0;
class Salaried: public Employee
{
private:
int managementLevel;
const int MIN_MANAGEMENT_LEVEL;
const int MAX_MANAGEMENT_LEVEL;
const double BONUS_PERCENT;
public:
Salaried(); //Default constructor
Salaried(string fname, string lname, char gen, int dep, double sal, Benefit ben, int manLevel); //Overloaded constructor with all paramters passed
Salaried(double sal, int manLevel);//Overloaded constructor with partial paramters passed
double calculatePay(); //Function inherited from the Parent Employee class
void displayEmployee(); //display Employee details specific to Employee and Salaried objects
};
Salaried::Salaried():Employee(), MIN_MANAGEMENT_LEVEL(0),MAX_MANAGEMENT_LEVEL(3),BONUS_PERCENT(10) //Default constructor of salaried class which is calling parent class default constructor and initializing constant private variables
{
managementLevel = MIN_MANAGEMENT_LEVEL;
}
Salaried::Salaried(string fname, string lname, char gen, int dep, double sal, Benefit ben, int manLevel):Employee(fname, lname, gen, dep, sal, ben), MIN_MANAGEMENT_LEVEL(0),MAX_MANAGEMENT_LEVEL(3),BONUS_PERCENT(10)
//Overloaded constructor of salaried class that is calling parent class constructor and initializing all private constant variables
{
if (manLevel >= MIN_MANAGEMENT_LEVEL && manLevel <= MAX_MANAGEMENT_LEVEL) //If value lies between min and max managementLevel
managementLevel = manLevel; //set managementLevel as entered
else if (manLevel < MIN_MANAGEMENT_LEVEL) //If value is less than min managementLevel
managementLevel = MIN_MANAGEMENT_LEVEL; //Initialize dependents to Min managementLevel
else if (manLevel > MAX_MANAGEMENT_LEVEL) //If value is greater than max managementLevel
managementLevel = MAX_MANAGEMENT_LEVEL; //Initialize dependents to Max managementLevels
}
Salaried::Salaried(double sal, int manLevel):Employee(), MIN_MANAGEMENT_LEVEL(0),MAX_MANAGEMENT_LEVEL(3),BONUS_PERCENT(10)
//Overloaded constructor of salaried class paramters that is calling parent class default constructor and initializing all private constant variables
{
if (manLevel >= MIN_MANAGEMENT_LEVEL && manLevel <= MAX_MANAGEMENT_LEVEL) //If value lies between min and max managementLevel
managementLevel = manLevel; //set managementLevel as entered
else if (manLevel < MIN_MANAGEMENT_LEVEL) //If value is less than min managementLevel
managementLevel = MIN_MANAGEMENT_LEVEL; //Initialize dependents to Min managementLevel
else if (manLevel > MAX_MANAGEMENT_LEVEL) //If value is greater than max managementLevel
managementLevel = MAX_MANAGEMENT_LEVEL; //Initialize dependents to Max managementLevels
this->annualSalary = sal;
}
double Salaried::calculatePay() //Function calculatePay is overridden and gives a different meaning for Salaried class
{
double actualBonusPercentage = managementLevel * BONUS_PERCENT / 100; //Bonus percent = management leve multiply by 0.1 which is a constant here
double BonusAmount = actualBonusPercentage * this->annualSalary; //Total yearly bonus amount = bonus percentage multiply by annual salary
this->annualSalary = this->annualSalary + BonusAmount;
return (this->annualSalary) / 52; //weekly pay should be calculated like total annual salary plus bonus amount and here we are assuming 52 weeks in an year
}
void Salaried::displayEmployee() //display Employee details specific to Employee and Salaried objects
{
cout << " Employee Information ";
cout << "________________________________________________________________ ";
cout << " Name: " << firstName << " " << lastName;
cout << " Gender: " << gender;
cout << " Dependents: " << dependents;
cout << " Annual Salary: " << fixed << setprecision(2) << annualSalary;
cout << " Weekly Salary: " << fixed << setprecision(2) << calculatePay();
cout << " ";
benefit.displayBenefits();
cout<<" Salaried Employee"<<endl;
cout<<"Level: "<<managementLevel<<endl; //displaying management level value
}
class Hourly: public Employee //Hourly class is inherited from employee class and inheritance level is set as public here
{
private:
double wage;
double hours;
string category;
const int MIN_WAGE; //Default value for MIN WAGE LEVEL
const int MAX_WAGE; //Default value for MAX WAGE LEVEL
const int MIN_HOUR; //Default value for MIN HOUR LEVEL
const int MAX_HOUR; //Default value for MAX HOUR LEVEL
public:
Hourly(); //Default constructor of Hourly class
Hourly(double wage, double hours, string category);
Hourly(string fname, string lname, char gen, int dep, double wage, double hours, Benefit ben, string category);
double calculatePay();
void displayEmployee();
};
double::Hourly::calculatePay()//Function calculatePay is overridden and gives a different meaning for Hourly class
{
return this->hours * this->wage; //Hourly employee pay would be equal to hours worked * hourly pay
}
Hourly::Hourly():Employee(),MIN_WAGE(10),MAX_WAGE(75),MIN_HOUR(0),MAX_HOUR(50)
{
wage = MIN_WAGE; //Initialize wage to default min wage value
hours = MIN_HOUR; //Initialize hour to default min hour value
category = "Unknown"; //Initialize category to default value
this->annualSalary = calculatePay()*50;
}
Hourly::Hourly(string fname, string lname, char gen, int dep, double wage, double hours, Benefit ben, string category):Employee(fname,lname, gen, dep, 0.0,ben),MIN_WAGE(10),MAX_WAGE(75),MIN_HOUR(0),MAX_HOUR(50)
//Overloaded constructor of Hourly class. The constructor will be calling overloaded constructor of parent class
{
double wge = wage;
if (wge >= MIN_WAGE && wge <= MAX_WAGE) //If value lies between min and max WAGE
this->wage = wge; //set WAGE as entered
else if (wge < MIN_WAGE) //If value is less than min WAGE
this->wage = MIN_WAGE; //Initialize dependents to Min WAGE
else if (wge > MAX_WAGE) //If value is greater than max WAGE
this->wage = MAX_WAGE; //Initialize dependents to Max WAGE
double hour = hours;
if (hour >= MIN_HOUR && hour <= MAX_HOUR) //If value lies between min and max Hour
this->hours = hour; //set Hour as entered
else if (hour < MIN_HOUR) //If value is less than min Hour
this->hours = MIN_HOUR; //Initialize dependents to Min Hour
else if (hour > MAX_HOUR) //If value is greater than max Hour
this->hours = MAX_HOUR; //Initialize dependents to Max Hour
if ( category == "temporary" || category == "part time" || category == "full time" ) //If value lies between min and max Hour
this->category = category; //set category as entered
else
this->category = "Unknown"; //set Category to unknown otherwise
this->annualSalary = calculatePay()*50;
}
Hourly::Hourly(double wage, double hours, string category):Employee(),MIN_WAGE(10),MAX_WAGE(75),MIN_HOUR(0),MAX_HOUR(50)
{
double wge = wage;
if (wge >= MIN_WAGE && wge <= MAX_WAGE) //If value lies between min and max WAGE
this->wage = wge; //set WAGE as entered
else if (wge < MIN_WAGE) //If value is less than min WAGE
this->wage = MIN_WAGE; //Initialize dependents to Min WAGE
else if (wge > MAX_WAGE) //If value is greater than max WAGE
this->wage = MAX_WAGE; //Initialize dependents to Max WAGE
double hour = hours;
if (hour >= MIN_HOUR && hour <= MAX_HOUR) //If value lies between min and max Hour
this->hours = hour; //set Hour as entered
else if (hour < MIN_HOUR) //If value is less than min Hour
this->hours = MIN_HOUR; //Initialize dependents to Min Hour
else if (hour > MAX_HOUR) //If value is greater than max Hour
this->hours = MAX_HOUR; //Initialize dependents to Max Hour
if ( category == "temporary" || category == "part time" || category == "full time" ) //If value lies between min and max Hour
this->category = category; //set category as entered
else
this->category = "Unknown"; //set Category to unknown otherwise
this->annualSalary = calculatePay()*50;
}
void Hourly::displayEmployee() //Function displayEmployee is overridden and display Employee specific plus Hourly specific information
{
cout << " Employee Information ";
cout << "________________________________________________________________ ";
cout << " Name: " << firstName << " " << lastName;
cout << " Gender: " << gender;
cout << " Dependents: " << dependents;
cout << " Annual Salary: " << fixed << setprecision(2) << annualSalary;
cout << " Weekly Salary: " << fixed << setprecision(2) << calculatePay();
cout << " ";
benefit.displayBenefits();
cout<<" Hourly Employee"<<endl;
cout<<"Category: "<<this->category<<endl;//displaying category value
cout<<"Hours: "<<this->hours <<endl; //displaying Total hours value
cout<<"Wage: "<<this->wage<<endl;//displaying wage value
}
int main()
{
//display banner
cout << "Welcome to your first Object Oriented Program--Employee ClassCIS247C, Week 5 Lab";
cout << "Name: ";
cout << " ******************** Employee 1 ******************** ";
//declare object for Employee
Employee emp1;
string fname, lname;
string gender, dependents, salstr, healthins;
double sal, lifeinsur;
int vacation;
//prompt and read employee information
cout << "Please enter your First Name ";
cin >> fname;
cout << "Please enter your Last Name ";
cin >> lname;
cout << "Please enter your Gender ";
cin >> gender;
cout << "Please enter your Dependents ";
cin >> dependents;
cout << "Please enter your Annual Salary ";
cin >> salstr;
cout << "Please enter your Health insurance ";
cin >> healthins;
cout << "Please enter your life insurance ";
cin >> lifeinsur;
cout << " Please enter your vacation days ";
cin >> vacation;
Benefit bene(healthins,lifeinsur,vacation);
emp1.setBenefit(bene);
//set the employee information using setter methodds
emp1.setfirstName(fname);
emp1.setlastName(lname);
emp1.setGender(gender[0]);
/* Calling the new overloaded setters */
emp1.setdependents(dependents);
emp1.setannualSalary(salstr);
//display employee info
emp1.displayEmployee();
//Calling and displaying number of employee objects created
cout << " --- Number of Employee Object Created ---- ";
cout << "Number of Employees : " << Employee::getNumEmployees() << " ";
Benefit ben("HMO", 100, 16);
//create second object for Employee
//pass employee information as parameters
Salaried emp2 = Salaried("Jackie", "Chan", 'M', 1, 50000, ben,3);
cout << " ******************** Employee 2 ******************** ";
//display employee info
emp2.displayEmployee();
//Calling and displaying number of employee objects created
cout << " --- Number of Employee Object Created ---- ";
cout << "Number of Employees : " << Employee::getNumEmployees() << " ";
Benefit ben22("PPO", 5, 17);
//create second object for Employee
//pass employee information as parameters
Hourly emp3 = Hourly("James", "Bond", 'M', 0, 40, 50,ben22,"");
cout << " ******************** Employee 3 ******************** ";
//display employee info
emp3 .displayEmployee();
//Calling and displaying number of employee objects created
cout << " --- Number of Employee Object Created ---- ";
cout << "Number of Employees : " << Employee::getNumEmployees() << " ";
cout << " The end of the CIS247C Week5 iLab.";
return 0;
}
Sample OutPut
Welcome to your first Object Oriented Program--Employee ClassCIS247C, Week 5 Lab
Name:
******************** Employee 1 ********************
Please enter your First Name Nana
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 PPO
Please enter your life insurance 1.5
Please enter your vacation days 20
Employee Information
________________________________________________________________
Name: Nana Liu
Gender: F
Dependents: 2
Annual Salary: 60000.00
Weekly Salary: 1153.85
Benefit Information
________________________________________________________________
Health Insurance: PPO
Life Insurance: 1.50
Vacation: 20 days
--- Number of Employee Object Created ----
Number of Employees : 1
******************** Employee 2 ********************
Employee Information
________________________________________________________________
Name: Jackie Chan
Gender: M
Dependents: 1
Annual Salary: 50000.00
Weekly Salary: 1250.00
Benefit Information
________________________________________________________________
Health Insurance: HMO
Life Insurance: 100.00
Vacation: 16 days
Salaried Employee
Level: 3
--- Number of Employee Object Created ----
Number of Employees : 2
******************** Employee 3 ********************
Employee Information
________________________________________________________________
Name: James Bond
Gender: M
Dependents: 0
Annual Salary: 100000.00
Weekly Salary: 2000.00
Benefit Information
________________________________________________________________
Health Insurance: PPO
Life Insurance: 5.00
Vacation: 17 days
Hourly Employee
Category: Unknown
Hours: 50.00
Wage: 40.00
--- Number of Employee Object Created ----
Number of Employees : 3
The end of the CIS247C Week5 iLab.
--------------------------------
Process exited after 15.38 seconds with return value 0
Press any key to continue . . .
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.