Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Benefit.cpp
- #include "Employee.h"
- #include "Benefit.h"
- #include <iostream>
- #include <iomanip>
- Benefit::Benefit() : healthInsurance("not provided"), lifeInsurance(0.0), vacation(14)
- {
- }
- Benefit::Benefit(string health, double life, int vac) :
- healthInsurance(health),
- lifeInsurance(life),
- vacation(vac)
- {
- }
- Benefit::~Benefit()
- {
- }
- void Benefit::displayBenefits()
- {
- cout << "\nBenefit Information\n";
- cout << "----------------------------------------------------------------\n";
- cout << "Health Insurance: \t" << healthInsurance << "\n";
- cout << "Life Insurance: \t" << setprecision(2) << showpoint << lifeInsurance << "\n";
- cout << "Vacation Days: \t\t" << vacation << " days\n";
- }
- string Benefit::getHealthInsurance()
- {
- return healthInsurance;
- }
- void Benefit::setHealthInsurance(string newHealthInsurance)
- {
- healthInsurance = newHealthInsurance;
- }
- double Benefit::getLifeInsurance()
- {
- return lifeInsurance;
- }
- void Benefit::setLifeInsurance(double newLifeInsurance)
- {
- lifeInsurance = newLifeInsurance;
- }
- int Benefit::getVacation()
- {
- return vacation;
- }
- void Benefit::setVacation(int newVacation)
- {
- vacation = newVacation;
- }
- //Benefit.h
- #pragma once
- #include <string>
- using namespace std;
- class Benefit
- {
- private:
- string healthInsurance;
- double lifeInsurance;
- int vacation;
- public:
- Benefit();
- Benefit(string health, double life, int vac);
- ~Benefit();
- void displayBenefits();
- string getHealthInsurance();
- void setHealthInsurance(string);
- double getLifeInsurance();
- void setLifeInsurance(double);
- int getVacation();
- void setVacation(int);
- };
- //Employee.cpp
- #include <iostream>
- #include <iomanip>
- #include "Employee.h"
- #include "Benefit.h"
- 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'; //N stands for not identified
- const int NUMBER_WEEKS = 52;
- int Employee::numEmployees = 0;
- Employee::Employee() : benefit(), firstName("not given"), lastName("not given"), gender('U'), dependents(0), annualSalary(20000.0)
- {
- numEmployees++;
- }
- Employee::Employee(string first, string last, char gen, int dep, Benefit ben) :
- firstName(first),
- lastName(last),
- gender(gen),
- dependents(dep),
- benefit(ben)
- {
- numEmployees++;
- }
- Employee::~Employee()
- {
- numEmployees--;
- }
- double Employee::calculatePay()
- {
- return (annualSalary/NUMBER_WEEKS);
- }
- void Employee::displayEmployee()
- {
- cout << "Name:\t\t" << firstName << " " << lastName << "\n";
- cout << "Gender:\t" << gender << "\n";
- cout << "Dependents:\t" << dependents << "\n";
- cout << "Annual Salary:\t$" << setprecision(2) << showpoint << fixed << annualSalary << "\n";
- cout << "Weekly Pay:\t$" << setprecision(2) << showpoint << fixed << calculatePay() << "\n";
- benefit.displayBenefits();
- }
- string Employee::getFirstName()
- {
- return firstName;
- }
- void Employee::setFirstName(string name)
- {
- firstName = name;
- }
- string Employee::getLastName()
- {
- return lastName;
- }
- void Employee::setLastName(string name)
- {
- lastName = name;
- }
- char Employee::getGender()
- {
- return gender;
- }
- void Employee::setGender(char gen)
- {
- switch (gen)
- {
- case 'f':case 'F': case 'M':case 'm':
- gender = gen;
- break;
- default:
- gender = DEFAULT_GENDER;
- }
- }
- int Employee::getDependents()
- {
- return dependents;
- }
- void Employee::setDependents(int dep)
- {
- if (dep >= MIN_DEPENDENTS && dep <= MAX_DEPENDENTS)
- {
- dependents = dep;
- }
- else if (dep < MIN_DEPENDENTS)
- {
- dep = MIN_DEPENDENTS;
- }
- else
- {
- dependents = MAX_DEPENDENTS;
- }
- }
- void Employee::setDependents(string dep)
- {
- Employee::setDependents(atoi(dep.c_str()));
- }
- double Employee::getAnnualSalary()
- {
- return annualSalary;
- }
- void Employee::setAnnualSalary(double salary)
- {
- annualSalary = salary;
- }
- void Employee::setAnnualSalary(string sal)
- {
- Employee::setAnnualSalary( atof(sal.c_str()));
- }
- Benefit Employee::getBenefit()
- {
- return benefit;
- }
- void Employee::setBenefit(Benefit ben)
- {
- string tempString;
- double lifeInsurance;
- int vacation;
- benefit = ben;
- }
- int Employee::getNumEmployees()
- {
- return Employee::numEmployees;
- }
- //Employee.h
- #pragma once
- #include "Benefit.h"
- #include <string>
- using namespace std;
- void DislayApplicationInformation();
- void DisplayDivider(string);
- void DisplayDivider2(string);
- string GetInput (string);
- void TerminateApplication();
- class Employee
- {
- protected:
- string firstName;
- string lastName;
- char gender;
- int dependents;
- double annualSalary;
- Benefit benefit;
- public:
- Employee();
- Employee(string, string, char, int, Benefit);
- ~Employee();
- virtual double calculatePay() = 0;
- virtual void displayEmployee() = 0;
- 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);
- double getAnnualSalary();
- virtual void setAnnualSalary(double salary);
- void setAnnualSalary(string sal);
- Benefit getBenefit();
- void setBenefit(Benefit ben);
- static int getNumEmployees();
- private:
- static int numEmployees;
- };
- #include "Hourly.h"
- #include <iostream>
- //Hourly.cpp
- #include <iomanip>
- const double MIN_WAGE = 10;
- const double MAX_WAGE = 75;
- const double MIN_HOURS = 0;
- const double MAX_HOURS = 50;
- Hourly::Hourly() : Employee(), MIN_WAGE(10), MAX_WAGE(75), MIN_HOURS(0), MAX_HOURS(50)
- {
- wage = 0;
- hours = 0;
- category = "X";
- }
- Hourly::Hourly(double wage, double hours, string category) : Employee(), MIN_WAGE(10), MAX_WAGE(75), MIN_HOURS(0), MAX_HOURS(50)
- {
- setWage(wage);
- setHours(hours);
- setCategory(category);
- setAnnualSalary(calculatePay());
- }
- Hourly::Hourly(string firstName, string lastName, char gender, int dependents, double wage, double hours, Benefit benefit, string category) :
- Employee(firstName, lastName, gender, dependents, benefit), MIN_WAGE(10), MAX_WAGE(75), MIN_HOURS(0), MAX_HOURS(50)
- {
- setWage(wage);
- setHours(hours);
- setCategory(category);
- setAnnualSalary(calculatePay());
- }
- Hourly::~Hourly()
- {
- }
- double Hourly::calculatePay()
- {
- return getWage() * getHours();
- }
- void Hourly::setAnnualSalary(double salary)
- {
- Employee::setAnnualSalary(calculatePay()*50);
- }
- void Hourly::displayEmployee(void)
- {
- Employee::displayEmployee();
- cout<<"Hourly Employee\n";
- cout<<"Category:\t\t" << category << "\n";
- cout<<"Wage:\t\t\t" << wage << "\n";
- cout<<"Hours:\t\t\t" << hours << "\n";
- }
- double Hourly::getWage()
- {
- return wage;
- }
- void Hourly::setWage(double Wage)
- {
- if(Wage >= MIN_WAGE && Wage >= MAX_WAGE)
- wage = Wage;
- else if (Wage < MIN_WAGE)
- wage = MIN_WAGE;
- else if (Wage > MAX_WAGE)
- wage = MAX_WAGE;
- setAnnualSalary(calculatePay());
- }
- double Hourly::getHours()
- {
- return hours;
- }
- void Hourly::setHours(double Hours)
- {
- if (Hours >= MIN_HOURS && Hours <= MAX_HOURS)
- hours = Hours;
- else if(Hours < MIN_HOURS)
- hours = MIN_HOURS;
- else if(Hours > MAX_HOURS)
- hours = MAX_HOURS;
- setAnnualSalary(calculatePay());
- }
- string Hourly::getCategory()
- {
- return category;
- }
- void Hourly::setCategory(string cat)
- {
- if(category == "temporary" || category == "part time" || category == "full time")
- category = cat;
- else
- category = "Unknown";
- }
- //Hourly.h
- #pragma once
- #include "employee.h"
- class Hourly :
- public Employee
- {
- public:
- Hourly();
- Hourly(string, string, char, int, double, double, Benefit, string);
- Hourly(double, double, string);
- ~Hourly();
- double calculatePay();
- void displayEmployee();
- void setAnnualSalary(double salary);
- double getWage();
- void setWage(double wage);
- double getHours();
- void setHours(double hours);
- string getCategory();
- void setCategory(string category);
- private:
- const double MIN_WAGE;
- const double MAX_WAGE;
- const double MIN_HOURS;
- const double MAX_HOURS;
- double wage;
- double hours;
- string category;
- };
- //Main.cpp
- #include "Employee.h"
- #include "Hourly.h"
- #include "Salaried.h"
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- int main()
- {
- DislayApplicationInformation();
- DisplayDivider("Employee 1");
- Employee *employeeList1 = new Salaried(10000, 3);
- Benefit salariedBenefit;
- employeeList1->setFirstName(GetInput("First Name "));
- employeeList1->setLastName(GetInput("Last Name "));
- string tempString = GetInput("Gender ");
- char gender = tempString.at(0);
- employeeList1->setGender(gender);
- employeeList1->setDependents(GetInput("Dependents "));
- salariedBenefit.setHealthInsurance(GetInput("Health Insurance"));
- salariedBenefit.setLifeInsurance(atof(GetInput("Life Insurance").c_str()));
- salariedBenefit.setVacation(atoi(GetInput("Vacation").c_str()));
- employeeList1->setBenefit(salariedBenefit);
- DisplayDivider2("Employee Information");
- employeeList1->displayEmployee();
- cout << "\n--- Number of Employee Objects Created ----\t";
- cout << "Number of employees: " << Employee::getNumEmployees() << "\n";
- DisplayDivider("Employee 2");
- Employee *employeeList2 = new Hourly(50, 40, "full time");
- Benefit hourlyBenefit;
- employeeList2->setFirstName(GetInput("First Name "));
- employeeList2->setLastName(GetInput("Last Name "));
- tempString = GetInput("Gender ");
- gender = tempString.at(0);
- employeeList2->setGender(gender);
- employeeList2->setDependents(GetInput("Dependents "));
- hourlyBenefit.setHealthInsurance(GetInput("Health Insurance"));
- hourlyBenefit.setLifeInsurance(atof(GetInput("Life Insurance").c_str()));
- hourlyBenefit.setVacation(atoi(GetInput("Vacation").c_str()));
- employeeList2->setBenefit(hourlyBenefit);
- DisplayDivider2("Employee Information");
- employeeList2->displayEmployee();
- cout << "\n--- Number of Employee Objects Created ----\t";
- cout << "Number of employees: " << Employee::getNumEmployees() << "\n";
- TerminateApplication();
- return 0;
- }
- void DisplayDivider(string outputTitle)
- {
- cout << "************************" << outputTitle <<"************************\n";
- }
- void DislayApplicationInformation()
- {
- cout << "Welcome to your first Object Oriented Program\n";
- cout << "Employee Class CIS247C, Week 6 Lab\n";
- cout << "Name: Name\n";
- }
- void DisplayDivider2(string outputTitle)
- {
- cout << "\n" << outputTitle << endl;
- cout << "----------------------------------------------------------------\n";
- }
- string GetInput (string inputType)
- {
- string input;
- cout<<"Please enter your "<< inputType <<": ";
- getline(cin, input);
- return input;
- }
- void TerminateApplication()
- {
- cout << "\nThank you for using the Employee Class program\n";
- }
- //Salaried.cpp
- #include "Salaried.h"
- #include "Employee.h"
- #include <iostream>
- #include <iomanip>
- using namespace std;
- Salaried::Salaried() : Employee(), minManagementLevel(0), maxManagementLevel(3), bonusPercent(.10)
- {
- managementLevel = 0;
- }
- Salaried::Salaried(string firstName, string lastName, char gender, int dependents, double salary, Benefit ben, int managementLevel) :
- Employee (firstName, lastName, gender, dependents, ben), minManagementLevel(0), maxManagementLevel(3), bonusPercent(.10)
- {
- managementLevel = 0;
- }
- Salaried::Salaried(double salary, int managementLevel) : Employee(), minManagementLevel(0), maxManagementLevel(3), bonusPercent(.10)
- {
- managementLevel = managementLevel;
- annualSalary = salary;
- }
- Salaried::~Salaried()
- {
- }
- double Salaried::calculatePay()
- {
- return annualSalary;
- }
- void Salaried::displayEmployee()
- {
- Employee::displayEmployee();
- cout<<"Salaried Employee\n";
- cout<<"Management Level:\t" << managementLevel << "\n";
- }
- int Salaried::getManagementLevel()
- {
- return managementLevel;
- }
- void Salaried::setManagementLevel(int manLevel)
- {
- if (manLevel >= minManagementLevel && manLevel <= maxManagementLevel)
- managementLevel = manLevel;
- else if (manLevel < minManagementLevel)
- managementLevel = minManagementLevel;
- else if (manLevel > maxManagementLevel)
- managementLevel = maxManagementLevel;
- }
- //Salaried.h
- #pragma once
- #include "employee.h"
- class Salaried :
- public Employee
- {
- public:
- Salaried();
- Salaried(string, string, char, int, double, Benefit, int);
- Salaried(double, int);
- ~Salaried();
- double calculatePay();
- void displayEmployee();
- int getManagementLevel();
- void setManagementLevel(int manLevel);
- private:
- const int minManagementLevel;
- const int maxManagementLevel;
- const double bonusPercent;
- int managementLevel;
- };
Advertisement
Add Comment
Please, Sign In to add comment