I am having trouble making my salary and hourly information display I have: #inc
ID: 3809248 • Letter: I
Question
I am having trouble making my salary and hourly information display I have:
#include <iostream>
#include <string>
#include <stdlib.h>
#include <iomanip>
using namespace std;
const double MIN_SALARY = 50000;
const double MAX_SALARY = 250000;
const int MAX_DEPENDENTS = 10;
const int MIN_DEPENDENTS = 0;
const char DEFAULT_GENDER = 'N';
const int NUMBER_WEEKS = 52;
class Benefit
{
private:
string healthInsurance;
double lifeInsurance;
int vacation;
public:
Benefit()
{
this->healthInsurance = "not provided";
this->lifeInsurance = 0;
this->vacation = 14;
}
Benefit(string healthInsurance, double lifeInsurance, int vacation)
{
this->healthInsurance = healthInsurance;
this->lifeInsurance = lifeInsurance;
this->vacation = vacation;
}
Benefit(Benefit &mybenefit)
{
this->healthInsurance = mybenefit.healthInsurance;
this->lifeInsurance = mybenefit.lifeInsurance;
this->vacation = mybenefit.vacation;
}
string getHealthInsurance()
{
return healthInsurance;
}
void setHealthInsurance(string healthInsurance)
{
this->healthInsurance = healthInsurance;
}
double getLifeInsurance()
{
return lifeInsurance;
}
void setLifeInsurance(double lifeInsurance)
{
this->lifeInsurance = lifeInsurance;
}
int getVacation()
{
return vacation;
}
void setVacation(int vacation)
{
this->vacation = vacation;
}
void displayBenefits()
{
cout<<" Benefit Information ";
cout<<"____________________________________________________________ ";
cout<<"Health Insurance: " << healthInsurance << " ";
cout<<"Life Insurance: " << lifeInsurance << " ";
cout<<"Vacation: " << vacation << " days ";
}
};
class Employee
{ //declare static variable
private:
static int numEmployees;
protected:
string firstName;
string lastName;
char gender;
int dependents;
double annualSalary;
//declare a benefits object
Benefit benefits;
public:
Employee():benefits()//default constructor
{
firstName = "";
lastName = "";
gender = 'N';
dependents = 0;
annualSalary = 50000;
//each time a constructor is called, increment the the class level numEmployees variable
this->numEmployees += 1;
//Instantiate the Benefits object
//benefits();
}
//create a parameterized construct
Employee(string firstName, string lastName, char gender, int dependents, double salary, Benefit mybenefits):benefits(mybenefits)
{
//use the THIS keyword to distinguish between the class attributes and the parameters
this->firstName = firstName;
this->lastName = lastName;
this->gender = gender;
this->dependents = dependents;
this->annualSalary = salary;
//each time a constructor is called, increment the the class level numEmployees variable
this->numEmployees += 1;
}
//create the accessors and mutators for the benefit object
Benefit getBenefits()
{
return benefits;
}
void setBenefits(Benefit benefits)
{
this->benefits = benefits;
}
//a static method that returns the number of employee object that are created
static int getNumberEmployees()
{
return numEmployees;
}
//Accessors and mutators, one for each class attribute
string getFirstName()
{
return firstName;
}
void setFirstName(string name)
{
firstName = name;
}
string getLastName()
{
return lastName;
}
void setLastName(string name)
{
lastName = name;
}
char getGender()
{
return gender;
}
void setGender(char gen)
{
switch (gen)
{
case 'f':case 'F': case 'M':case 'm':
gender = gen;
break;
default:
gender = DEFAULT_GENDER;
}
}
int getDependents()
{
return dependents;
}
void setDependents(int dep)
{
if (dep >= MIN_DEPENDENTS && dep <= MAX_DEPENDENTS)
{
dependents = dep;
}
else if (dep < MIN_DEPENDENTS)
{
dep = MIN_DEPENDENTS;
}
else
{
dependents = MAX_DEPENDENTS;
}
}
double getAnnualSalary()
{
return annualSalary;
}
void setAnnualSalary(double salary)
{
if (salary >= MIN_SALARY && salary <= MAX_SALARY)
{
annualSalary = salary;
}
else if (salary < MIN_SALARY)
{
annualSalary = MIN_SALARY;
}
else
{
annualSalary = MAX_SALARY;
}
}
double calculatePay()
{
return annualSalary/NUMBER_WEEKS;
}
void displayEmployee()
{
cout<<"Employee Information ";
cout<<"____________________________________________________________ ";
cout<<"Name: " <<firstName << " " << lastName << " ";
cout<<"Gender: " << gender << " ";
cout<<"Dependents: " << dependents << " ";
cout<<"Annual Salary: " << setprecision(2)<<showpoint<<fixed<<annualSalary << " ";
cout<<"Weekly Salary: " << setprecision(2)<<showpoint<<fixed<<calculatePay()<<" ";
//show the benefits
this->benefits.displayBenefits();
}
};
int Employee::numEmployees=0;//supply initial value to static data members
void DisplayApplicationInformation()
{ cout<<"Welcome to your Object Oriented Program--Employee Class"
<<"CIS247C, Week 4 Lab"
<<"Name: Jose Gongora";
}
void DisplayDivider(string message)
{cout<<" *************** " + message + " ********************* ";}
string GetInput( string message)
{ string mystring;
cout<<"Please enter your "<<message;
getline(cin, mystring);
return mystring;
}
void TerminateApplication()
{ cout<<" The end of the CIS247C Week4 iLab. ";}
class Salaried : public Employee
{
private:
int Min_Managment_Level;
int Max_Managment_Level;
double Bonus_Percent;
int ManagementLevel;
public:
Salaried()
{
this->Min_Managment_Level = 0;
this->Max_Managment_Level = 3;
this->Bonus_Percent = 10;
this->ManagementLevel = 0;
}
Salaried(int Min_Managment_Level, int Max_Managment_Level, double Bonus_Percent, int ManagementLevel)
{
this->Min_Managment_Level = Min_Managment_Level;
this->Max_Managment_Level = Max_Managment_Level;
this->Bonus_Percent = Bonus_Percent;
this->ManagementLevel = ManagementLevel;
}
Salaried(Salaried &mysalary)
{
this->Min_Managment_Level = mysalary.Min_Managment_Level;
this->Max_Managment_Level = mysalary.Max_Managment_Level;
this->Bonus_Percent = mysalary.Bonus_Percent;
this->ManagementLevel = mysalary.ManagementLevel;
}
void setManagementLevel(int ManagementLevel)
{
ManagementLevel = ManagementLevel;
}
int getManagementLevel()
{
return ManagementLevel;
}
};
class Hourly : public Employee
{
private:
double Min_Wage;
double Max_Wage;
double Min_Hours;
double Max_Hours;
double Wage;
double Hours;
string Category;
public:
Hourly()
{
this->Min_Wage = 10;
this->Max_Wage = 75;
this->Min_Hours = 0;
this->Max_Hours = 50;
this->Wage = 0;
this->Hours = 0;
this->Category ="";
}
Hourly(double Wage, double Hours, string Category)
{
this->Wage = Wage;
this->Hours = Hours;
this->Category = Category;
}
Hourly(Hourly &myhours)
{
this->Wage = myhours.Wage;
this->Hours = myhours.Hours;
this->Category = myhours.Category;
}
void setWage(double Wage)
{
Wage = Wage;
}
double getWage()
{
return Wage;
}
void setHours(double Hours)
{
Hours = Hours;
}
double getHours()
{
return Hours;
}
void setCategory(string Category)
{
Category = Category;
}
string getCategory()
{
return Category;
}
};
int main()
{
//create two employee objects
Employee employee1; //declare and instantiate the object variable
Employee employee2; //declare and instantiate the object variable
Employee employee3; //declare and instantiate the object variable
char gender;
double lifeInsurance;
int vacation;
string str;
//always provide some type of application information to the user--don't leave them cold!
DisplayApplicationInformation();
//use a utility method to keep a consistent format to the output
DisplayDivider("Employee 1");
//access the employee objects members using the DOT notation
employee1.setFirstName(GetInput("First Name "));
employee1.setLastName(GetInput("Last Name "));
str = GetInput("Gender ");
gender = str.at(0);
employee1.setGender(gender);
employee1.setDependents(atoi( GetInput("Dependents ").c_str()));
employee1.setAnnualSalary(atof(GetInput("Annual Salary ").c_str()));
Benefit theBenefits;
//set the benefit information
theBenefits.setHealthInsurance(GetInput("Health Insurance"));
theBenefits.setLifeInsurance(atof(GetInput("Life Insuarance").c_str()));
theBenefits.setVacation(atoi(GetInput("Vocation Days").c_str()));
//set the benefit information
employee1.setBenefits(theBenefits);
//now show all the information, including the benefit information
employee1.displayEmployee();
//use the Class level static method to display the number of employees
cout<<"--- Number of Employee Object Created ----";
cout<<" Number of employees: " << Employee::getNumberEmployees();
DisplayDivider("Employee 2");
//access the employee objects members using the DOT notation
employee2.setFirstName(GetInput("First Name "));
employee2.setLastName(GetInput("Last Name "));
str = GetInput("Gender ");
gender = str.at(0);
employee2.setGender(gender);
employee2.setDependents(atoi( GetInput("Dependents ").c_str()));
employee2.setAnnualSalary(atof(GetInput("Annual Salary ").c_str()));
//set the benefit information
theBenefits.setHealthInsurance(GetInput("Health Insurance"));
theBenefits.setLifeInsurance(atof(GetInput("Life Insuarance").c_str()));
theBenefits.setVacation(atoi(GetInput("Vocation Days").c_str()));
//set the benefit information
employee2.setBenefits(theBenefits);
//set the salary information
Salaried mySalary;
mySalary.setManagementLevel(atoi(GetInput("Management Level").c_str()));
//now show all the information, including the benefit information
employee2.displayEmployee();
cout<<" --- Number of Employee Object Created ----";
cout<<" Number of employees: " <<Employee::getNumberEmployees();
DisplayDivider("Employee 3");
//access the employee objects members using the DOT notation
employee3.setFirstName(GetInput("First Name "));
employee3.setLastName(GetInput("Last Name "));
str = GetInput("Gender ");
gender = str.at(0);
employee3.setGender(gender);
employee3.setDependents(atoi( GetInput("Dependents ").c_str()));
employee3.setAnnualSalary(atof(GetInput("Annual Salary ").c_str()));
//set the benefit information
theBenefits.setHealthInsurance(GetInput("Health Insurance"));
theBenefits.setLifeInsurance(atof(GetInput("Life Insuarance").c_str()));
theBenefits.setVacation(atoi(GetInput("Vocation Days").c_str()));
//set the benefit information
employee3.setBenefits(theBenefits);
//set the Hourly information
Hourly myHours;
myHours.setCategory(GetInput("Category").c_str());
myHours.setWage(atoi( GetInput("Wage").c_str()));
myHours.setHours(atoi( GetInput("Hours").c_str()));
//now show all the information, including the benefit information
employee3.displayEmployee();
cout<<" --- Number of Employee Object Created ----";
cout<<" Number of employees: " <<Employee::getNumberEmployees();
system("pause");
TerminateApplication();
}
I need it to display like:
For salaried employee, the following information needs to be displayed:
For hourly employee, the following information needs to be displayed:
Nante Jackie Chan Gender: Dependents: Annual Salary 50000.00 Weekly Salary 1250.00 Benefit Information Health Insurance HMO 100.00 Life Insurance Vacation 16 days Salaried Employee Managenent level: Number of Enployee Object Created Number of enployees 2Explanation / Answer
#include #include #include #include using namespace std; const double MIN_SALARY = 50000; const double MAX_SALARY = 250000; const int MAX_DEPENDENTS = 10; const int MIN_DEPENDENTS = 0; const char DEFAULT_GENDER = 'N'; const int NUMBER_WEEKS = 52; class Benefit { private: string healthInsurance; double lifeInsurance; int vacation; public: Benefit() { this.healthInsurance = "not provided"; this.lifeInsurance = 0; this.vacation = 14; } Benefit(string healthInsurance, double lifeInsurance, int vacation) { this.healthInsurance = healthInsurance; this.lifeInsurance = lifeInsurance; this.vacation = vacation; } Benefit(Benefit &mybenefit) { this.healthInsurance = mybenefit.healthInsurance; this.lifeInsurance = mybenefit.lifeInsurance; this.vacation = mybenefit.vacation; } string getHealthInsurance() { return healthInsurance; } void setHealthInsurance(string healthInsurance) { this->healthInsurance = healthInsurance; } double getLifeInsurance() { return lifeInsurance; } void setLifeInsurance(double lifeInsurance) { this->lifeInsurance = lifeInsurance; } int getVacation() { return vacation; } void setVacation(int vacation) { this->vacation = vacation; } void displayBenefits() { coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.