#include <iostream>
#include <string>
#include <stdlib.h>
#include <iomanip>
using namespace std;
int MAX_dependents = 10;
char default_gender = 'U';
void displayApplicat ion()
{
cout << "Welcome to your first Object Oriented Program--Employee Class \nCIS247C, Week 2 Lab \nName: Anthony Rodriguez";
}
void displayDivider( string message)
{
cout << "\n************ **** " + message + "************** **\n";
}
void terminateApplic ation()
{
cout << "\n\nThe end of the CIS247 Week1 iLab. \n";
}
class Employee
{
private:
string firstName;
string lastName;
char gender;
int dependents;
public:
Employee();
Employee(string first, string last, char gen, int dep);
void displayE();
string getFirstName();
void setFirstName(st ring first);
string getLastName();
void setLastName(str ing last);
char getGender();
void setGender(char gen);
int getDependents() ;
void setDependents(i nt dep);
void setDependents(s tring dep);
static int getNumEmployees ();
static int numEmployees;
class Salaried;
class Hourly;
};
Employee::Emplo yee()
{
firstName = "N/A";
lastName = "N/A";
gender = 'U';
dependents = 0;
numEmployees = 0;
string firName;
string lasName;
char gen;
int dep;
char payType;
cout << "Please enter employee's first name: ";
cin >> firName;
cout << "Please enter employee's last name: ";
cin >> lasName;
cout << "Please enter employee's gender: ";
cin >> gen;
cout << "Please enter employee's number of dependents: ";
cin >> dep;
cout << "Please enter employee's pay category (Y = Yearly or H = Hourly): ";
cin >> payType;
payType = (toupper(payTyp e));
if (payType = 'Y')
{
Employee::Salar ied;
}
if (payType = 'H')
{
Employee::Hourl y;
}
setFirstName(fi rName);
setLastName(las Name);
setGender(toupp er(gen));
setDependents(d ep);
}
Employee::Emplo yee(string first, string last, char gen, int dep)
{
firstName = first;
lastName = last;
gender = gen;
dependents = dep;
}
string Employee::getFi rstName()
{
return firstName;
}
void Employee::setFi rstName(string first)
{
firstName = first;
}
string Employee::getLa stName()
{
return lastName;
}
void Employee::setLa stName(string last)
{
lastName = last;
}
char Employee::getGe nder()
{
return gender;
}
void Employee::setGe nder(char gen)
{
gender = gen;
if ((gender == 'M') || (gender == 'F'))
{
gender = gen;
}
else
{
gender = default_gender;
}
}
int Employee::getDe pendents()
{
return dependents;
}
void Employee::setDe pendents(int dep)
{
dependents = dep;
if (dependents > MAX_dependents)
{
dependents = MAX_dependents;
}
}
void Employee::setDe pendents(string dep)
{
dependents = atoi(dep.c_str( ));
}
int Employee::getNu mEmployees()
{
return numEmployees;
}
void Employee::displ ayE()
{
cout << endl;
cout << "Employee Information\n" << endl;
cout << fixed << setprecision(2) ;
cout << "First Name: " << firstName << endl;
cout << "Last Name: " << lastName << endl;
cout << "Gender: " << gender << endl;
cout << "Dependents : " << dependents << endl;
cout << endl;
}
class Salaried : public Employee
{
private:
int min_management;
int max_management;
double bonus_percent;
int managementLevel ;
double annualsalary;
public:
Salaried();
Salaried(double salary, int mLevel);
double getAnnualSalary ();
void setAnnualSalary (double salary);
double calculateP();
int getManagementLe vel();
void setManagementLe vel(int mLevel);
void displaySalaried ();
};
Salaried::Salar ied()
{
annualsalary = 20000;
managementLevel = 0;
int sal;
int manageLevel;
cout << "Please enter employee's annual salary: ";
cin >> sal;
cout << "Please enter employee's management level: ";
cin >> manageLevel;
setAnnualSalary (sal);
setManagementLe vel(manageLevel );
}
Salaried::Salar ied(double salary, int mLevel)
{
annualsalary = salary;
managementLevel = mLevel;
}
double Salaried::getAn nualSalary()
{
return annualsalary;
}
void Salaried::setAn nualSalary(doub le salary)
{
annualsalary = salary;
}
int Salaried::getMa nagementLevel()
{
return managementLevel ;
}
void Salaried::setMa nagementLevel(i nt mLevel)
{
managementLevel = mLevel;
}
double Salaried::calcu lateP()
{
double weeklyPay = 0.0;
weeklyPay = (annualsalary / 52);
return weeklyPay;
}
void Salaried::displ aySalaried()
{
cout << "Annual Salary: " << annualsalary << endl;
cout << "Weekly Pay: " << calculateP() << endl;
cout << "Management Level: " << managementLevel << endl;
}
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();
Hourly(double eWage, double eHours, string eCategory);
double getWage();
void setWage(double eWage);
double getHours();
void setHours(double eHours);
string getCategory();
void setCategory(str ing eCategory);
void displayHourly() ;
};
Hourly::Hourly( )
{
wage = 0;
hours = 0;
category = "";
double empWage;
double empHours;
string empCategory;
cout << "Please enter employee's hourly wage: ";
cin >> empWage;
cout << "Please enter employee's hours working: ";
cin >> empHours;
cout << "Please enter employee's work category (Full, Part, or Temporary): ";
cin >> empCategory;
setWage(empWage );
setHours(empHou rs);
setCategory(emp Category);
}
Hourly::Hourly( double eWage, double eHours, string eCategory)
{
wage = eWage;
hours = eHours;
category = eCategory;
}
double Hourly::getWage ()
{
return wage;
}
void Hourly::setWage (double eWage)
{
wage = eWage;
}
double Hourly::getHour s()
{
return hours;
}
void Hourly::setHour s(double eHours)
{
hours = eHours;
}
string Hourly::getCate gory()
{
return category;
}
void Hourly::setCate gory(string eCategory)
{
category = eCategory;
}
void Hourly::display Hourly()
{
cout << "Wage: " << wage << endl;
cout << "Hours: " << hours << endl;
cout << "Category: " << category << endl;
}
int Employee::numEm ployees = 0;
int main()
{
int numEmp;
displayApplicat ion();
displayDivider( "Employee 1");
Employee practiceOne;
//Salaried practiceSalary;
practiceOne.dis playE();
//practiceOne.Ben efits.displayBe nefits();
//practiceSalary. displaySalaried ();
Employee::numEm ployees++;
numEmp = Employee::getNu mEmployees();
cout << "--- Number of Employee Object Created ----" << endl;
cout << "Number of employees: " << numEmp << endl;
}
So my question or problem is that I want to give the user the choice between Yearly or Hourly worker which will make the program choose either Yearly class or Hourly class. I am not entirely sure how to do this. Please someone help me.
#include <string>
#include <stdlib.h>
#include <iomanip>
using namespace std;
int MAX_dependents = 10;
char default_gender = 'U';
void displayApplicat ion()
{
cout << "Welcome to your first Object Oriented Program--Employee Class \nCIS247C, Week 2 Lab \nName: Anthony Rodriguez";
}
void displayDivider( string message)
{
cout << "\n************ **** " + message + "************** **\n";
}
void terminateApplic ation()
{
cout << "\n\nThe end of the CIS247 Week1 iLab. \n";
}
class Employee
{
private:
string firstName;
string lastName;
char gender;
int dependents;
public:
Employee();
Employee(string first, string last, char gen, int dep);
void displayE();
string getFirstName();
void setFirstName(st ring first);
string getLastName();
void setLastName(str ing last);
char getGender();
void setGender(char gen);
int getDependents() ;
void setDependents(i nt dep);
void setDependents(s tring dep);
static int getNumEmployees ();
static int numEmployees;
class Salaried;
class Hourly;
};
Employee::Emplo yee()
{
firstName = "N/A";
lastName = "N/A";
gender = 'U';
dependents = 0;
numEmployees = 0;
string firName;
string lasName;
char gen;
int dep;
char payType;
cout << "Please enter employee's first name: ";
cin >> firName;
cout << "Please enter employee's last name: ";
cin >> lasName;
cout << "Please enter employee's gender: ";
cin >> gen;
cout << "Please enter employee's number of dependents: ";
cin >> dep;
cout << "Please enter employee's pay category (Y = Yearly or H = Hourly): ";
cin >> payType;
payType = (toupper(payTyp e));
if (payType = 'Y')
{
Employee::Salar ied;
}
if (payType = 'H')
{
Employee::Hourl y;
}
setFirstName(fi rName);
setLastName(las Name);
setGender(toupp er(gen));
setDependents(d ep);
}
Employee::Emplo yee(string first, string last, char gen, int dep)
{
firstName = first;
lastName = last;
gender = gen;
dependents = dep;
}
string Employee::getFi rstName()
{
return firstName;
}
void Employee::setFi rstName(string first)
{
firstName = first;
}
string Employee::getLa stName()
{
return lastName;
}
void Employee::setLa stName(string last)
{
lastName = last;
}
char Employee::getGe nder()
{
return gender;
}
void Employee::setGe nder(char gen)
{
gender = gen;
if ((gender == 'M') || (gender == 'F'))
{
gender = gen;
}
else
{
gender = default_gender;
}
}
int Employee::getDe pendents()
{
return dependents;
}
void Employee::setDe pendents(int dep)
{
dependents = dep;
if (dependents > MAX_dependents)
{
dependents = MAX_dependents;
}
}
void Employee::setDe pendents(string dep)
{
dependents = atoi(dep.c_str( ));
}
int Employee::getNu mEmployees()
{
return numEmployees;
}
void Employee::displ ayE()
{
cout << endl;
cout << "Employee Information\n" << endl;
cout << fixed << setprecision(2) ;
cout << "First Name: " << firstName << endl;
cout << "Last Name: " << lastName << endl;
cout << "Gender: " << gender << endl;
cout << "Dependents : " << dependents << endl;
cout << endl;
}
class Salaried : public Employee
{
private:
int min_management;
int max_management;
double bonus_percent;
int managementLevel ;
double annualsalary;
public:
Salaried();
Salaried(double salary, int mLevel);
double getAnnualSalary ();
void setAnnualSalary (double salary);
double calculateP();
int getManagementLe vel();
void setManagementLe vel(int mLevel);
void displaySalaried ();
};
Salaried::Salar ied()
{
annualsalary = 20000;
managementLevel = 0;
int sal;
int manageLevel;
cout << "Please enter employee's annual salary: ";
cin >> sal;
cout << "Please enter employee's management level: ";
cin >> manageLevel;
setAnnualSalary (sal);
setManagementLe vel(manageLevel );
}
Salaried::Salar ied(double salary, int mLevel)
{
annualsalary = salary;
managementLevel = mLevel;
}
double Salaried::getAn nualSalary()
{
return annualsalary;
}
void Salaried::setAn nualSalary(doub le salary)
{
annualsalary = salary;
}
int Salaried::getMa nagementLevel()
{
return managementLevel ;
}
void Salaried::setMa nagementLevel(i nt mLevel)
{
managementLevel = mLevel;
}
double Salaried::calcu lateP()
{
double weeklyPay = 0.0;
weeklyPay = (annualsalary / 52);
return weeklyPay;
}
void Salaried::displ aySalaried()
{
cout << "Annual Salary: " << annualsalary << endl;
cout << "Weekly Pay: " << calculateP() << endl;
cout << "Management Level: " << managementLevel << endl;
}
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();
Hourly(double eWage, double eHours, string eCategory);
double getWage();
void setWage(double eWage);
double getHours();
void setHours(double eHours);
string getCategory();
void setCategory(str ing eCategory);
void displayHourly() ;
};
Hourly::Hourly( )
{
wage = 0;
hours = 0;
category = "";
double empWage;
double empHours;
string empCategory;
cout << "Please enter employee's hourly wage: ";
cin >> empWage;
cout << "Please enter employee's hours working: ";
cin >> empHours;
cout << "Please enter employee's work category (Full, Part, or Temporary): ";
cin >> empCategory;
setWage(empWage );
setHours(empHou rs);
setCategory(emp Category);
}
Hourly::Hourly( double eWage, double eHours, string eCategory)
{
wage = eWage;
hours = eHours;
category = eCategory;
}
double Hourly::getWage ()
{
return wage;
}
void Hourly::setWage (double eWage)
{
wage = eWage;
}
double Hourly::getHour s()
{
return hours;
}
void Hourly::setHour s(double eHours)
{
hours = eHours;
}
string Hourly::getCate gory()
{
return category;
}
void Hourly::setCate gory(string eCategory)
{
category = eCategory;
}
void Hourly::display Hourly()
{
cout << "Wage: " << wage << endl;
cout << "Hours: " << hours << endl;
cout << "Category: " << category << endl;
}
int Employee::numEm ployees = 0;
int main()
{
int numEmp;
displayApplicat ion();
displayDivider( "Employee 1");
Employee practiceOne;
//Salaried practiceSalary;
practiceOne.dis playE();
//practiceOne.Ben efits.displayBe nefits();
//practiceSalary. displaySalaried ();
Employee::numEm ployees++;
numEmp = Employee::getNu mEmployees();
cout << "--- Number of Employee Object Created ----" << endl;
cout << "Number of employees: " << numEmp << endl;
}
So my question or problem is that I want to give the user the choice between Yearly or Hourly worker which will make the program choose either Yearly class or Hourly class. I am not entirely sure how to do this. Please someone help me.
Comment