Jun 8, 2015 at 12:23am UTC
#include <iostream>
#include <string>
#include <cstdlib>
#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
{
string healthInsurance;
double lifeInsurance;
int vacation;
public:
Benefit(): healthInsurance("not provided"), lifeInsurance(0), vacation(14){}
Benefit(string HealthInsurance, double LifeInsurance, int Vacation):
healthInsurance(HealthInsurance), lifeInsurance(LifeInsurance),
vacation(Vacation){}
Benefit(Benefit &mybenefit): healthInsurance(mybenefit.healthInsurance),
lifeInsurance(mybenefit.lifeInsurance), vacation(mybenefit.vacation){}
string getHealthInsurance()
{
return healthInsurance;
}
void setHealthInsurance(string HealthInsurance)
{
healthInsurance=HealthInsurance;
}
double getLifeInsurance()
{
return lifeInsurance;
}
void setLifeInsurance(double LifeInsurance)
{
lifeInsurance=LifeInsurance;
}
int getVacation()
{
return vacation;
}
void setVacation(int Vacation)
{
vacation=Vacation;
}
void displayBenefits()
{
cout<<"\nBenefit Information\n";
cout<<"____________________________________________________________\n";
cout<<"Health Insurance:\t"<<healthInsurance<<"\n";
cout<<"Life Insurance:\t\t"<<lifeInsurance<<"\n";
cout<<"Vacation:\t\t"<<vacation<<"days\n";
}
};
class Employee
{
static int numEmployees;
protected:
string firstName;
string lastName;
char gender;
int dependents;
double annualSalary;
Benefit benefits;
public:
Employee(): benefits() firstName(""), lastName(""), gender('N'), dependents(0),
annualSalary(50000)
{
numEmployees++;
}
Employee(string FirstName, string LastName, char Gender, int Dependents,
double salary, Benefit Mybenefits): benefits(Mybenefits),
firstName(FirstName), lastName(LastName), gender(Gender),
dependents(Dependents), annualSalary(salary)
{
numEmployees++;
}
Benefit getBenefits()
{
return benefits;
}
void setBenefits(Benefit Benefits)
{
benefits=Benefits;
}
static int getNumberEmployees()
{
return numEmployees;
}
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;
break;
}
}
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\n";
cout<<"____________________________________________________________\n";
cout<<"Name: \t\t" <<firstName<<" "<<lastName<<"\n";
cout<<"Gender:\t\t"<<gender<<"\n";
cout<<"Dependents: \t"<<dependents << "\n";
cout<<"Annual Salary:\t"<<setprecision(2)<<showpoint<<fixed<<annualSalary<<"\n";
cout<<"Weekly Salary:\t"<<calculatePay()<<"\n";
benefits.displayBenefits();
}
};
class Salaried : public Employee()
{
private:
const int MIN_MANAGEMENT_LEVEL=0;
const int MAX_MANAGEMENT_LEVEL=3;
const double BONUS_PERCENT=.10;
int managementLevel;
public:
Salaried(): managementLevel(0){}
Salaried(string firstName, string lastName, char gender, int dependents,
double salary, Benefit mybenefits):benefits(mybenefits), int manLevel):
Employee(firstName, lastName, gender, dependents, salary, mybenefits){}
Salaried(double sal, int manLevel): annualSalary(sal), managmentLevel(manLevel){}
double calculatePay()
{
return Employee::calculatePay()*(1+(managementLevel*BONUS_PERCENT));
}
void displayEmployee()
{
cout<<"Employee Information\n";
cout<<"____________________________________________________________\n";
cout<<"Name: \t\t"<<firstName<<" "<<lastName<<"\n";
cout<<"Gender:\t\t"<<gender<<"\n";
cout<<"Dependents: \t"<<dependents <<"\n";
cout<<"Annual Salary:\t" << setprecision(2)<<showpoint<<fixed<<annualSalary<<"\n";
cout<<"Weekly Salary:\t"<<calculatePay()<<"\n";
cout<<"Management Level: "<<managementLevel<<endl;
benefits.displayBenefits();
}
int getManagementLevel()
{
return managementLevel;
}
void setManagementLevel(int manLevel);
{
if (manlevel<4) managementLevel=manLevel;
else cerr<<"Management Level Error" << endl;
}
};
Jun 8, 2015 at 12:23am UTC
class Hourly : public Employee()
{
private:
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(double Wage=0, double Hours=0, string Category="X"):
wage(Wage), hours(Hours), category(Category){}
Hourly(string firstName, string lastName, char gender, int dependents,
double salary, Benefit mybenefits):benefits(mybenefits), int manLevel):
Employee(firstName, lastName, gender, dependents, salary, mybenefits)
{}
double calculatePay()
{
return wage * hours;
}
void setAnnualSalary(double salary)
{
salary=Employee::calculatePay() * 50;
}
void displayEmployee()
{
cout<<"Employee Information\n";
cout<<"____________________________________________________________\n";
cout<<"Name: \t\t"<<firstName<<" "<<lastName<<"\n";
cout<<"Gender:\t\t"<<gender<<"\n";
cout<<"Dependents: \t"<<dependents<<"\n";
cout<<"Annual Salary:\t"<<setprecision(2)<<showpoint<<fixed<<annualSalary<<"\n";
cout<<"Weekly Salary:\t"<<calculatePay()<<"\n";
cout<<"Category "<<category<<endl;
benefits.displayBenefits();
}
double getWage()
{
return wage;
}
void setWage(double Wage)
{
wage=Wage;
}
double getHours();
{
return hours;
}
void setHours(double Hours)
{
hours=Hours;
}
string getCategory()
{
return categeory;
}
void setCategory(string Category)
{
if (category=="temporary" || category=="part time" || category=="full time")
category=Category;
else
cerr<<"Category Error" << endl;
}
};
int Employee::numEmployees=0;
void DisplayApplicationInformation()
{
cout<<"Welcome the Basic User Interface Program"
<<"CIS247, Week 5 Lab"
<<"Name: Alicia Long";
}
void DisplayDivider(string message)
{
cout<<"\n*************** "+message+" *********************\n";
}
string GetInput( string message)
{
string mystring;
cout<<"Please enter your "<<message;
getline(cin, mystring);
return mystring;
}
void TerminateApplication()
{
cout<<"\nThe end of the CIS247C Week4 iLab.\n";
}
int main()
{
char gender;
double lifeInsurance;
int vacation;
string str;
Benefit theBenefits;
DisplayApplicationInformation();
DisplayDivider("Employee 1");
Employee genericEmp;
genericEmp.setFirstName(GetInput("First Name "));
genericEmp.setLastName(GetInput("Last Name "));
str=GetInput("Gender ");
gender=str[0];
genericEmp.setGender(gender);
genericEmp.setDependents(atoi( GetInput("Dependents ").c_str()));
genericEmp.setAnnualSalary(atof(GetInput("Annual Salary ").c_str()));
theBenefits.setHealthInsurance(GetInput("Health Insurance"));
theBenefits.setLifeInsurance(atof(GetInput("Life Insuarance").c_str()));
theBenefits.setVacation(atoi(GetInput("Vocation Days").c_str()));
genericEmp.setBenefits(theBenefits);
genericEmp.displayEmployee();
cout<<"\n--- Number of Employee Object Created ----";
cout<<"\tNumber of employees: " << Employee::getNumberEmployees();
DisplayDivider("Employee 2");
Salaried salariedEmp;
salariedEmp.setFirstName(GetInput("First Name "));
salariedEmp.setLastName(GetInput("Last Name "));
str=GetInput("Gender ");
gender=str.at(0);
salariedEmp.setGender(gender);
salariedEmp.setDependents(atoi( GetInput("Dependents ").c_str()));
theBenefits.setHealthInsurance(GetInput("Health Insurance"));
theBenefits.setLifeInsurance(atof(GetInput("Life Insuarance").c_str()));
theBenefits.setVacation(atoi(GetInput("Vocation Days").c_str()));
salariedEmp.setBenefits(theBenefits);
salariedEmp.setManagementLevel(3);
salariedEmp.displayEmployee();
cout<<"\n--- Number of Employee Object Created ----";
cout<<"\tNumber of employees: " << Employee::getNumberEmployees();
DisplayDivider("Employee 3");
Hourly hourEmp(genericEmp.getFirstName(), genericEmp.getLastName(), genericEmp.getGender(),
genericEmp.getDependents(), 40.0, 50.0, genericEmp.getBenefits(), "Full Time");
hourEmp.setFirstName(GetInput("First Name "));
hourEmp.setLastName(GetInput("Last Name "));
str=GetInput("Gender ");
gender=str.at(0);
hourEmp.setGender(gender);
hourEmp.setDependents(atoi( GetInput("Dependents ").c_str()));
theBenefits.setHealthInsurance(GetInput("Health Insurance"));
theBenefits.setLifeInsurance(atof(GetInput("Life Insuarance").c_str()));
theBenefits.setVacation(atoi(GetInput("Vocation Days").c_str()));
hourEmp.setBenefits(theBenefits);
hourEmp.displayEmployee();
cout<<"\n--- Number of Employee Object Created ----";
cout<<"\tNumber of employees: " << Employee::getNumberEmployees();
TerminateApplication();
}
Jun 8, 2015 at 1:32am UTC
Well, that's a long program. Can you format it with the code tag? Also it would be of great help if you point out what errors are you running into.
Jun 8, 2015 at 1:59am UTC
How can I show the numbers?
And also it keeps saying "cout is ambiguous"
I'm mostly having problems with int main part
Last edited on Jun 8, 2015 at 2:01am UTC