C++ I NEED THE CODE TO RUN THROUGH MICROSOFT VISUAL STUDIOS AND A SAMPLE OUTPUT
ID: 3866720 • Letter: C
Question
C++ I NEED THE CODE TO RUN THROUGH MICROSOFT VISUAL STUDIOS AND A SAMPLE OUTPUT WOULD BE APPRECIATED!!
I need my existing code updated with the following:
STEP 1 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.
STEP 2 Modify the Employee Class
1. Define calculatePay() as a pure virtual function.
2. Define displayEmployee() as a pure virtual function.
3. When class Employee contains two pure virtual functions, it becomes an abstract class.
STEP 3 Create Generalized Input Methods
1. Reuse method getInput() from the previous Lab to prompt the user to enter Employee information.
STEP 4 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.
STEP 5 SAMPLE OUTPUT OF WHAT THE PROGRAM SHOULD LOOK LIKE WHEN FINISHED
MY CODE THAT NEEDS TO BE UPDATED:
#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 iEmployee {
public:
virtual double calculatePay() = 0;
};*/
class Employee //: public iEmployee
{
protected:
static int numEmployees;
//member variables of Employee class
protected:
string firstName;
string lastName;
char gender;
int dependents;
double annualSalary;
public:
Benefit benefit;
//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;
}
//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
{
const int MIN_MANAGEMENT_LEVEL = 0;
const int MAX_MANAGEMENT_LEVEL = 3;
const double BONUS_PERCENT = .10;
int managementLevel;
public:
Salaried() :Employee()
{
managementLevel = MIN_MANAGEMENT_LEVEL;
}
Salaried(string fname, string lname, char gen, int dep, double salary, Benefit ben, int manLevel) :Employee(fname, lname, gen, dep, salary, ben)
{
firstName = fname;
lastName = lname;
gender = gen;
dependents = dep;
annualSalary = salary;
benefit = ben;
if (manLevel > MAX_MANAGEMENT_LEVEL && manLevel < MIN_MANAGEMENT_LEVEL)
managementLevel = MIN_MANAGEMENT_LEVEL;
else
managementLevel = manLevel;
}
Salaried(double sal, int manLevel) :Employee()
{
annualSalary = sal;
if (manLevel > MAX_MANAGEMENT_LEVEL && manLevel < MIN_MANAGEMENT_LEVEL)
managementLevel = MIN_MANAGEMENT_LEVEL;
else
managementLevel = manLevel;
}
double calculatePay()
{
return annualSalary / 52 + managementLevel*BONUS_PERCENT;
}
void setmanagementLevel(int manLevel)
{
if (manLevel > MAX_MANAGEMENT_LEVEL && manLevel < MIN_MANAGEMENT_LEVEL)
managementLevel = MIN_MANAGEMENT_LEVEL;
else
managementLevel = manLevel;
}
void displayEmployee()
{
cout << " Employee Information ";
cout << "________________________________________________________________ ";
cout << " Name: " << firstName << " " << lastName;
cout << " Gender: " << gender;
cout << " Dependents: " << dependents;
cout << " Management Level : " << managementLevel;
cout << " Annual Salary: " << fixed << setprecision(2) << annualSalary;
cout << " Weekly Salary: " << fixed << setprecision(2) << calculatePay();
cout << " ";
benefit.displayBenefits();
}
};
class Hourly :public Employee
{
const double MIN_WAGE = 10;
const double MAX_WAGE = 75;
const double MIN_HOURS = 0;
const double MAX_HOURS = 50;
double wage;
double hours;
string category;
public:
Hourly() :Employee()
{
wage = MIN_WAGE;
hours = MIN_HOURS;
category = "NOT ASSIGNED";
}
void setWage(double wage)
{
if (wage > MAX_WAGE && wage < MIN_WAGE)
this->wage = MIN_WAGE;
else
this->wage = wage;
}
void setHours(double hours)
{
if (hours > MAX_HOURS && hours < MIN_HOURS)
this->hours = MIN_HOURS;
else
this->hours = hours;
}
void setCategory(string category)
{
if (category._Equal("temporay") && category._Equal("part time") && category._Equal("full time"))
this->category = category;
else
category = "temporary";
}
Hourly(double wage, double hours, string category) :Employee()
{
if (wage > MAX_WAGE && wage < MIN_WAGE)
this->wage = MIN_WAGE;
else
this->wage = wage;
if (hours > MAX_HOURS && hours < MIN_HOURS)
this->hours = MIN_HOURS;
else
this->hours = hours;
if (category._Equal("temporay") || category._Equal("part time") || category._Equal("full time"))
this->category = category;
else
category = "temporary";
}
Hourly(string fname, string lname, char gen, int dep, double wage, double hours, Benefit ben, string category)
:Employee(fname, lname, gen, dep, wage, ben)
{
if (hours > MAX_HOURS && hours < MIN_HOURS)
this->hours = MIN_HOURS;
else
this->hours = hours;
if (category._Equal("temporay") || category._Equal("part time") || category._Equal("full time"))
this->category = category;
else
category = "temporary";
}
double calculatePay()
{
return wage * hours;
}
void setannualSalary(double salary)
{
annualSalary = salary * 50;
}
void displayEmployee()
{
cout << " Employee Information ";
cout << "________________________________________________________________ ";
cout << " Name: " << firstName << " " << lastName;
cout << " Gender: " << gender;
cout << " Dependents: " << dependents;
cout << " No. Of Hours : " << hours;
cout << " category of Worker: " << category;
cout << " Annual Salary: " << fixed << setprecision(2) << annualSalary;
cout << " Weekly Salary: " << fixed << setprecision(2) << calculatePay();
cout << " ";
benefit.displayBenefits();
}
};
int main()
{
//display banner
cout << "Welcome to your first Object Oriented Program--Employee ClassCIS247C, Week 6 Lab";
cout << "Name: ";
cout << " ******************** Employee 1 ******************** ";
//declare object for Employee
Salaried emp1;
Hourly worker;
string fname, lname;
string gender, dependents, salstr, healthins, category;
double sal, lifeinsur, wage, hours;
int vacation, manLevel;
//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;
cout << "Please Enter management Level (0-3)";
cin >> manLevel;
emp1.setmanagementLevel(manLevel);
emp1.benefit.setHealthInsurance(healthins);
emp1.benefit.setLifeInsurance(lifeinsur);
emp1.benefit.setVacation(vacation);
//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();
//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 >> sal;
cout << "Please enter your Health insurance ";
cin >> healthins;
cout << "Please enter your life insurance ";
cin >> lifeinsur;
cout << " Please enter your vacation days ";
cin >> vacation;
cout << "Please Enter number of hours (0-50)";
cin >> hours;
cout << "Please Enter Wages Rate ";
cin >> wage;
cout << "Please Enter worker Category(temporary, part time, and full time) ";
cin >> category;
worker.setannualSalary(sal);
worker.setWage(wage);
worker.setHours(hours);
worker.setCategory(category);
worker.benefit.setHealthInsurance(healthins);
worker.benefit.setLifeInsurance(lifeinsur);
worker.benefit.setVacation(vacation);
//set the employee information using setter methodds
worker.setfirstName(fname);
worker.setlastName(lname);
worker.setGender(gender[0]);
/* Calling the new overloaded setters */
worker.setdependents(dependents);
emp1.setannualSalary(salstr);
//display employee info
worker.displayEmployee();
//Calling and displaying number of employee objects created
cout << " --- Number of Employee Object Created ---- ";
cout << "Number of Employees : " << Employee::getNumEmployees() << " ";
Benefit ben("North West Mutual", 5000000, 14);
//create second object for Employee
//pass employee information as parameters
Employee emp2 = Employee("Mary", "Noia", 'F', 2, 150000, ben);
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() << " ";
cout << " The end of the CIS247C Week6 iLab.";
return 0;
}
Explanation / Answer
Modified the code accoring to requirements in question. When comparing category for Hourly, the ._Equal() was showning an error, I changed it to == . Also the condition should use || and not && . And there was a spelling mistake in temporary. Fixed that. Also made a getInput() function as indicated in question to accept generalized informaton of an employee and reusing that in main.
For salaried employee, I guess the hourly pay is not being calculated properly. I noticed this when I tested it with the employee1 details as shown in screen shot. The screen shot in question shows weekly salary of 1500. But your code outputs 1154. Since I do not have the details on how pay is calculated from pervious question, you will have to look into it.
Please do rate the answer if it helped. Thank you.
#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" << endl;
}
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 //: public iEmployee
{
protected:
static int numEmployees;
//member variables of Employee class
protected:
string firstName;
string lastName;
char gender;
int dependents;
double annualSalary;
public:
Benefit benefit;
//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);
}
//Static method
static int getNumEmployees()
{
//Return number of employee objects created
return numEmployees;
}
//method that displays employee information, pure virtual function
virtual void displayEmployee() = 0;
//method that calculates pay , pure virtual function
virtual double calculatePay() = 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()
{
managementLevel = MIN_MANAGEMENT_LEVEL;
}
Salaried(string fname, string lname, char gen, int dep, double salary, Benefit ben, int manLevel) :Employee(fname, lname, gen, dep, salary, ben)
{
firstName = fname;
lastName = lname;
gender = gen;
dependents = dep;
annualSalary = salary;
benefit = ben;
if (manLevel > MAX_MANAGEMENT_LEVEL && manLevel < MIN_MANAGEMENT_LEVEL)
managementLevel = MIN_MANAGEMENT_LEVEL;
else
managementLevel = manLevel;
}
Salaried(double sal, int manLevel) :Employee()
{
annualSalary = sal;
if (manLevel > MAX_MANAGEMENT_LEVEL && manLevel < MIN_MANAGEMENT_LEVEL)
managementLevel = MIN_MANAGEMENT_LEVEL;
else
managementLevel = manLevel;
}
double calculatePay()
{
return annualSalary / 52 + managementLevel*BONUS_PERCENT;
}
void setmanagementLevel(int manLevel)
{
if (manLevel > MAX_MANAGEMENT_LEVEL && manLevel < MIN_MANAGEMENT_LEVEL)
managementLevel = MIN_MANAGEMENT_LEVEL;
else
managementLevel = manLevel;
}
void displayEmployee()
{
cout << " Employee Information ";
cout << "________________________________________________________________ ";
cout << " Name: " << firstName << " " << lastName;
cout << " Gender: " << gender;
cout << " Dependents: " << dependents;
cout << " Management Level : " << managementLevel;
cout << " Annual Salary: " << fixed << setprecision(2) << annualSalary;
cout << " Weekly Salary: " << fixed << setprecision(2) << calculatePay();
cout << " ";
benefit.displayBenefits();
}
};
class Hourly :public Employee
{
const double MIN_WAGE = 10;
const double MAX_WAGE = 75;
const double MIN_HOURS = 0;
const double MAX_HOURS = 50;
double wage;
double hours;
string category;
public:
Hourly() :Employee()
{
wage = MIN_WAGE;
hours = MIN_HOURS;
category = "NOT ASSIGNED";
}
void setWage(double wage)
{
if (wage > MAX_WAGE && wage < MIN_WAGE)
this->wage = MIN_WAGE;
else
this->wage = wage;
}
void setHours(double hours)
{
if (hours > MAX_HOURS && hours < MIN_HOURS)
this->hours = MIN_HOURS;
else
this->hours = hours;
}
void setCategory(string category)
{
if (category == "temporary" || category == "part time" || category == "full time")
this->category = category;
else
this->category = "temporary";
}
Hourly(double wage, double hours, string category) :Employee()
{
if (wage > MAX_WAGE && wage < MIN_WAGE)
this->wage = MIN_WAGE;
else
this->wage = wage;
if (hours > MAX_HOURS && hours < MIN_HOURS)
this->hours = MIN_HOURS;
else
this->hours = hours;
if (category == "temporary" || category == "part time" || category == "full time")
this->category = category;
else
this->category = "temporary";
}
Hourly(string fname, string lname, char gen, int dep, double wage, double hours, Benefit ben, string category)
:Employee(fname, lname, gen, dep, wage, ben)
{
if (hours > MAX_HOURS && hours < MIN_HOURS)
this->hours = MIN_HOURS;
else
this->hours = hours;
if (category == "temporary" || category == "part time" || category == "full time")
this->category = category;
else
this->category = "temporary";
}
double calculatePay()
{
return wage * hours;
}
void setannualSalary(double salary)
{
annualSalary = salary * 50;
}
void displayEmployee()
{
cout << " Employee Information ";
cout << "________________________________________________________________ ";
cout << " Name: " << firstName << " " << lastName;
cout << " Gender: " << gender;
cout << " Dependents: " << dependents;
cout << " No. Of Hours : " << hours;
cout << " Category of Worker: " << category;
cout << " Annual Salary: " << fixed << setprecision(2) << annualSalary;
cout << " Weekly Salary: " << fixed << setprecision(2) << calculatePay();
cout << " ";
benefit.displayBenefits();
}
};
//generalized input method for accepting employee details
void getInput(Employee *emp1)
{
string fname, lname;
string gender, dependents, salstr, healthins;
double lifeinsur;
int vacation;
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;
emp1->benefit.setHealthInsurance(healthins);
emp1->benefit.setLifeInsurance(lifeinsur);
emp1->benefit.setVacation(vacation);
//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);
}
int main()
{
//display banner
cout << "Welcome to your first Object Oriented Program--Employee ClassCIS247C, Week 6 Lab";
cout << "Name: ";
cout << " ******************** Employee 1 ******************** ";
//declare object for Employee
Employee *emp1 = new Salaried(10000, 3);;
Employee *emp2 = new Hourly(50, 40, "full time");
//prompt and read employee information
getInput(emp1);
//display employee info
emp1->displayEmployee();
//prompt and read employee information
cout << " ******************** Employee 2 ******************** ";
getInput(emp2);
//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() << " ";
cout << " The end of the CIS247C Week6 iLab." << endl;
return 0;
}
output
Welcome to your first Object Oriented Program--Employee ClassCIS247C, Week 6 LabName:
******************** 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 21
Employee Information
________________________________________________________________
Name: Nana Liu
Gender: F
Dependents: 2
Management Level : 3
Annual Salary: 60000.00
Weekly Salary: 1154.15
Benefit Information
________________________________________________________________
Health Insurance: PPO
Life Insurance: 1.50
Vacation: 21 days
******************** 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 Annual Salary 100000
Please enter your Health insurance HMO
Please enter your life insurance 100
Please enter your vacation days 18
Employee Information
________________________________________________________________
Name: Jackie Chan
Gender: M
Dependents: 1
No. Of Hours : 40.00
Category of Worker: full time
Annual Salary: 100000.00
Weekly Salary: 2000.00
Benefit Information
________________________________________________________________
Health Insurance: HMO
Life Insurance: 100.00
Vacation: 18 days
--- Number of Employee Object Created ----
Number of Employees : 2
The end of the CIS247C Week6 iLab.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.