#include <iostream>
#include <string>
#include <stdlib.h>
#include <iomanip>
using namespace std;
int MAX_dependents = 10;
char default_gender = 'U';
void displayApplication()
{
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 terminateApplication()
{
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(string first);
string getLastName();
void setLastName(string last);
char getGender();
void setGender(char gen);
int getDependents();
void setDependents(int dep);
void setDependents(string dep);
static int getNumEmployees();
static int numEmployees;
class Salaried;
class Hourly;
};
Employee::Employee()
{
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(payType));
if (payType = 'Y')
{
Employee::Salaried;
}
if (payType = 'H')
{
Employee::Hourly;
}
setFirstName(firName);
setLastName(lasName);
setGender(toupper(gen));
setDependents(dep);
}
Employee::Employee(string first, string last, char gen, int dep)
{
firstName = first;
lastName = last;
gender = gen;
dependents = dep;
}
string Employee::getFirstName()
{
return firstName;
}
void Employee::setFirstName(string first)
{
firstName = first;
}
string Employee::getLastName()
{
return lastName;
}
void Employee::setLastName(string last)
{
lastName = last;
}
char Employee::getGender()
{
return gender;
}
void Employee::setGender(char gen)
{
gender = gen;
if ((gender == 'M') || (gender == 'F'))
{
gender = gen;
}
else
{
gender = default_gender;
}
}
int Employee::getDependents()
{
return dependents;
}
void Employee::setDependents(int dep)
{
dependents = dep;
if (dependents > MAX_dependents)
{
dependents = MAX_dependents;
}
}
void Employee::setDependents(string dep)
{
dependents = atoi(dep.c_str());
}
int Employee::getNumEmployees()
{
return numEmployees;
}
void Employee::displayE()
{
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 getManagementLevel();
void setManagementLevel(int mLevel);
void displaySalaried();
};
Salaried::Salaried()
{
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);
setManagementLevel(manageLevel);
}
Salaried::Salaried(double salary, int mLevel)
{
annualsalary = salary;
managementLevel = mLevel;
}
double Salaried::getAnnualSalary()
{
return annualsalary;
}
void Salaried::setAnnualSalary(double salary)
{
annualsalary = salary;
}
int Salaried::getManagementLevel()
{
return managementLevel;
}
void Salaried::setManagementLevel(int mLevel)
{
managementLevel = mLevel;
}
double Salaried::calculateP()
{
double weeklyPay = 0.0;
weeklyPay = (annualsalary / 52);
return weeklyPay;
}
void Salaried::displaySalaried()
{
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(string 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(empHours);
setCategory(empCategory);
}
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::getHours()
{
return hours;
}
void Hourly::setHours(double eHours)
{
hours = eHours;
}
string Hourly::getCategory()
{
return category;
}
void Hourly::setCategory(string eCategory)
{
category = eCategory;
}
void Hourly::displayHourly()
{
cout << "Wage: " << wage << endl;
cout << "Hours: " << hours << endl;
cout << "Category: " << category << endl;
}
int Employee::numEmployees = 0;
int main()
{
int numEmp;
displayApplication();
displayDivider("Employee 1");
Employee practiceOne;
//Salaried practiceSalary;
practiceOne.displayE();
//practiceOne.Benefits.displayBenefits();
//practiceSalary.displaySalaried();
Employee::numEmployees++;
numEmp = Employee::getNumEmployees();
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.