Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Scenario/Summary The objective of the lab is to take the UML Class diagram and e

ID: 3865916 • Letter: S

Question

Scenario/Summary

The objective of the lab is to take the UML Class diagram and enhance last week's Employee class by making the following changes:

Create a class called Salaried that is derived from Employee.

Create a class called Hourly that is also derived from Employee.

Override the base class calculatePay() method.

Override the displayEmployee() method.

Software Citation Requirements

This course uses open-source software, which must be cited when used for any student work. Citation requirements are on the Open Source Applications page.
Please review the installation instruction files to complete your assignment.

Deliverables

Due this week:

Capture the Console output window and paste into a Word document.

Zip the project folder file.

Upload the zip file and screenshots (Word document).

Required Software

Connect to the Lab here. (Links to an external site.)Links to an external site.

Lab Steps

STEP 1: Understand the UML Diagram

Notice the change in UML diagram. It is common practice to leave out the accessors and mutators (getters and setters) from UML class diagrams, since there can be so many of them. Unless otherwise specified, it is assumed that there is an accessor (getter) and a mutator (setter) for every class attribute.

STEP 2: Create the Project

Create a new project and name it CIS247C_WK5_Lab_LASTNAME. Copy all the source files from the Week 4 project into the Week 5 project.

Before you move on to the next step, build and execute the Week 5 project.

STEP 3: Modify the Employee Class

Using the updated Employee class diagram, modify the attributes to be protected.

Delete the iEmployee interface class, and remove the reference from the Employee class.

STEP 4: Create the Salaried Class

Using the UML Diagrams from Step 1, create the Salaried classes, ensuring to specify that the Salary class inherits from the Employee class.

For each of the constructors listed in the Salaried class, ensure to invoke the appropriate base class constructor and pass the correct arguments to the base class constructor. This will initialize the protected attributes and update the numEmployees counter.

The valid management levels are 0, 1, 2, and 3, and should be implemented as a constant.

Override the calculatePay method to add a 10 percent bonus for each of the management levels (i.e., bonus percentage = managementLevel * .10). The bonus percentage should be implemented as a constant.

Override the displayEmployee() method to add the management level to the employee information.

STEP 5: Create the Hourly Class

Using the UML Diagrams from Step 1, create the Hourly classes, ensuring to specify that the Hourly class inherits from the Employee class.

For each of the constructors listed in the Hourly class, ensure to invoke the appropriate base class constructor and pass the correct arguments to the base class constructor. This will initialize the protected attributes and update the numEmployees counter.

The valid category types are "temporary", "part time", and "full time".

The provided hours must be more than 0 hours and less than 50 hours, and the limits should be implemented as constants.

The provided wage must be between 10 and 75, and the limits should be implemented as constants.

Override the calculatePay method by multiplying the wages by the number of hours.

Override the Employee setAnnualSalary method and set the annual salary by multiplying the weekly pay by 50.

Override the displayEmployee() method to add the category to the hourly employee information.

STEP 6: Modify the Main Method

Using previous weeks' assignments as an example, create at least one Employee, Hourly, and Salaried employee.

For each object created, display the number of employees created.

For each object created, write statements to exercise each of the public methods listed in the Class diagram.

For each object created, invoke the object's displayEmployee() method to display the employee's information.

For employee, the following information needs to be displayed:

For salaried employee, the following information needs to be displayed:

For hourly employee, the following information needs to be displayed:

STEP 7: Compile and Test

When done, compile and run your code.

Then, debug any errors until your code is error-free.

Check your output to ensure that you have the desired output, modify your code as necessary, and rebuild.

Below is the complete sample program output for your reference.

Explanation / Answer

//main.cpp

#include <iostream>

#include <iomanip>

#include <string>

#include "Employee.h"

#include "Salaried.h"

#include "Hourly.h"

//function prototypes from Basic UI program week1

void DisplayApplicationInformation();

void DisplayDivider(string outputTitle);

string GetInput(string inputType);

void TerminateApplication();

int main()

{

DisplayApplicationInformation();

Employee employee1; //instantiate employee1 object using default constructor.

DisplayDivider("Employee 1");

//This section prompts for user input

string firstName = GetInput("first name");

employee1.setFirstName(firstName);

string lastName = GetInput("last name");

employee1.setLastName(lastName);

string gender = GetInput("gender");

char firstCharacterGender = gender[0]; //takes value of gender, places in array, and assigns first charcter to char firstCharacterGender.

employee1.setGender(firstCharacterGender);

string dependents = GetInput("dependents");

employee1.setDependents(dependents);

string annualSalary = GetInput("annual salary");

employee1.setAnnualSalary(annualSalary);

string healthInsurance = GetInput("health insurance");

employee1.getBenefit().setHealthInsurance(healthInsurance); //changed benefit to getBenefit. Make sure it works correctly.

string lifeInsurance = GetInput("life insurance");

employee1.getBenefit().setLifeInsurance(stod(lifeInsurance)); //changed benefit to getBenefit. Make sure it works correctly.

string vacation = GetInput("vacation");

employee1.getBenefit().setVacation(stoi(vacation)); //changed benefit to getBenefit. Make sure it works correctly.

employee1.displayEmployee();

cout << " ----Number of Employee Objects Created----" << endl;

cout << "Number of Employees: " << Employee::getNumEmployees() << endl; //getNumEmployees called using class name.

//BEGIN section that creates a salaried employee object.

DisplayDivider("Employee 2");

Salaried salariedEmployee1;

//Enter the employee information to the object

firstName = GetInput("first name");

salariedEmployee1.setFirstName(firstName);

lastName = GetInput("last name");

salariedEmployee1.setLastName(lastName);

gender = GetInput("gender");

firstCharacterGender = gender[0];

salariedEmployee1.setGender(firstCharacterGender);

dependents = GetInput("dependents");

salariedEmployee1.setDependents(dependents);

annualSalary = GetInput("annual salary");

salariedEmployee1.setAnnualSalary(annualSalary);

healthInsurance = GetInput("health insurance");

salariedEmployee1.getBenefit().setHealthInsurance(healthInsurance);

lifeInsurance = GetInput("life insurance");

salariedEmployee1.getBenefit().setLifeInsurance(stod(lifeInsurance));

vacation = GetInput("vacation");

salariedEmployee1.getBenefit().setVacation(stoi(vacation));

salariedEmployee1.displayEmployee(); //display salaried employee information.

cout << " ----Number of Employee Objects Created----" << endl;

cout << "Number of Employees: " << Employee::getNumEmployees() << endl; //getNumEmployees called using class name.

//END salaried employee section.

//BEGIN section that creates a hourly employee object.

DisplayDivider("Employee 3");

Hourly hourlyEmployee1;

//enter the employee information

firstName = GetInput("first name");

hourlyEmployee1.setFirstName(firstName);

lastName = GetInput("last name");

hourlyEmployee1.setLastName(lastName);

gender = GetInput("gender");

firstCharacterGender = gender[0];

hourlyEmployee1.setGender(firstCharacterGender);

dependents = GetInput("dependents");

hourlyEmployee1.setDependents(dependents);

annualSalary = GetInput("annual salary"); //this section may need to be changed

hourlyEmployee1.setAnnualSalary();

healthInsurance = GetInput("health insurance");

hourlyEmployee1.getBenefit().setHealthInsurance(healthInsurance);

lifeInsurance = GetInput("life insurance");

hourlyEmployee1.getBenefit().setLifeInsurance(stod(lifeInsurance));

vacation = GetInput("vacation");

hourlyEmployee1.getBenefit().setVacation(stoi(vacation));

hourlyEmployee1.displayEmployee(); //display hourly employee.

cout << " ----Number of Employee Objects Created----" << endl;

cout << "Number of Employees: " << Employee::getNumEmployees() << endl; //getNumEmployees called using class name.

//END hourly employee section.

TerminateApplication();

return 0;

}

void DisplayApplicationInformation()

{

cout << "Welcome to the Employee Class Test Program." << endl;

}

void DisplayDivider(string outputTitle)

{

cout << ' ' << "******************************** " + outputTitle + " ***********************************" << endl;

}

string GetInput(string inputType)

{

cout << "Please enter " + inputType + ": ";

string strInput;

getline(cin, strInput);

return strInput;

}

void TerminateApplication()

{

cout <<' ' << "Thank you for using the application!" << endl;

}

==============================================================================

//Hourly.h

#include "Employee.h"

#ifndef HOURLY_H

#define HOURLY_H

using namespace std;

class Hourly : public Employee

{

private:

//UML diagram showed these as Doubles compiler would only allow int.

static const int MIN_WAGE = 10; //error message said "Error 12 error C2864: 'Hourly::MIN_WAGE' : only static const integral data members can be initialized within a class

static const int MAX_WAGE = 75;

static const int MIN_HOURS = 0;

static const int MAX_HOURS = 50;

double wage;

double hours;

string category;

public:

Hourly();

Hourly(double wage, double hours, string category);

Hourly(string fname, string lname, char gen, int dep, double wage, double hours, Benefit ben, string category);

double calculatePay();

void displayEmployee();

void setAnnualSalary(); //this was not in UML diagram, but lab instructions told us to override this function.

//setters and getters

double getWage();

void setWage();

double getHours();

void setHours();

string getCategory();

void setCategory();

};

#endif

=================================================================================

//Hourly.cpp

#include <iostream>

#include <iomanip>

#include <string>

#include "Hourly.h"

#include "Employee.h"

Hourly::Hourly() //may need to add and initialize constants here.

{

wage = 0;

hours = 0;

category = "Unknown";

}

Hourly::Hourly(double wge, double hrs, string cat)

{

wage = wge;

hours = hrs;

category = cat;

}

Hourly::Hourly(string fname, string lname, char gen, int dep, double wge, double hrs, Benefit ben, string cat) : Employee(fname, lname, gen, dep, ben)

{

wage = wge;

hours = hrs;

category = cat;

}

double Hourly::calculatePay() //this should override function in Employee.

{

return wage * hours;

}

void Hourly::setAnnualSalary() //monitor this function may need to change.

{

annualSalary = calculatePay() * 50;

}

void Hourly::displayEmployee()

{

Employee::displayEmployee();

cout << " Hourly Employee" << endl;

cout << "Category: " << category << endl;

cout << "Wage: " << wage << endl;

cout << "Hours: " << hours << endl;

}

================================================================================

//Employee.h

#ifndef EMPLOYEE_H //inclusion guard

#define EMPLOYEE_H

#include "Benefit.h"

using namespace std;

class Employee

{

protected: //protected attributes

string firstName;

string lastName;

char gender;

int dependents;

double annualSalary;

Benefit benefit; // may have to add setters and getters for this.

private:

static int numEmployees; //static variable keeps count of total number of employees.

public: //member functions

Employee(); //default constructor

Employee(string first, string last, char gen, int dep, Benefit benefit); //multi-arg constructor

double calculatePay();

void displayEmployee();

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();

void setAnnualSalary(double salary);

void setAnnualSalary(string salary);

static int getNumEmployees();

Benefit getBenefit();

void setBenefit(Benefit ben);

};

#endif

==================================================================================

//Employee.cpp

#include <iostream>

#include <iomanip>

#include <string>

#include "Employee.h"

Employee::Employee() //no-arg default constructor

{

firstName = "Not Given";

lastName = "Not Given";

gender = 'U';

dependents = 0;

annualSalary = 20000;

numEmployees++;

}

Employee::Employee(string first, string last, char gen, int dep, Benefit ben) : benefit(ben) //constructor with arguments

{

firstName = first;

lastName = last;

gender = gen;

dependents = dep;

numEmployees++;

}

double Employee::calculatePay()

{

return annualSalary / 52;

}

void Employee::displayEmployee()

{

cout << " Employee Information" << endl;

cout << "------------------------------------------------" << endl;

cout << "Name: " << firstName << " " << lastName << endl;

cout << "Gender: " << gender << endl;

cout << "Dependents: " << dependents << endl;

cout << "Annual Salary: $" << setprecision(2) << showpoint << fixed << annualSalary << endl;

cout << "Weekly Salary: $" << setprecision(2) << showpoint << fixed << calculatePay() << endl;

benefit.displayBenefits();

}

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;

}

int Employee::getDependents()

{

return dependents;

}

void Employee::setDependents(int dep)

{

dependents = dep;

}

void Employee::setDependents(string dep)

{

dependents = stoi(dep); //string is converted to int.

}

double Employee::getAnnualSalary()

{

return annualSalary;

}

void Employee::setAnnualSalary(double salary)

{

annualSalary = salary;

}

void Employee::setAnnualSalary(string salary)

{

annualSalary = stod(salary); //string is converted to double.

}

Benefit Employee::getBenefit() //accessor function for benefit object in Employee.

{

return benefit;

}

void Employee::setBenefit(Benefit ben) //mutator function for benefit object in Employee.

{

benefit = ben;

}

int Employee::numEmployees = 0; //initialize static variable numEmployees to 0.

int Employee::getNumEmployees() //static member function

{

return numEmployees;

}

===============================================================================

//Salaried.h

#include "Employee.h"

#ifndef SALARIED_H

#define SALARIED_H

using namespace std;

class Salaried : public Employee

{

private:

static const int MIN_MANAGEMENT_LEVEL = 0;

static const int MAX_MANAGEMENT_LEVEL = 3;

static const int BONUS_PERCENT = 10; //UML diagram showed this as a double??? and is was not a decimal in UML diagram.

int managementLevel;

public:

Salaried(); //default constructor

Salaried(string fname, string lname, char gen, int dep, double sal, Benefit ben, int manLevel); //multi-arg constructor

Salaried(double sal, int manLevel); //multi-arg constructor

double calculatePay();

void displayEmployee();

//setters and getters.

int getManagementLevel();

void setManagementLevel();

};

#endif

============================================================================

//Salaried.cpp

#include <iostream>

#include <iomanip>

#include <string>

#include "Salaried.h"

#include "Employee.h"

Salaried::Salaried()

{

managementLevel = 0;

}

Salaried::Salaried(string fname, string lname, char gen, int dep, double sal, Benefit ben, int manLevel) : Employee(fname, lname, gen, dep, ben)

{

managementLevel = manLevel;

annualSalary = sal;

}

Salaried::Salaried(double sal, int manLevel)

{

annualSalary = sal;

managementLevel = manLevel;

}

double Salaried::calculatePay()

{

return Employee::calculatePay() * (1 + (managementLevel * BONUS_PERCENT));

}

void Salaried::displayEmployee()

{

Employee::displayEmployee();

cout << " Salaried Employee" << endl;

cout << "Management Level: " << managementLevel << endl;

}

===========================================================================

//Benefit.h

#ifndef BENEFIT_H

#define BENEFIT_H

using namespace std;

class Benefit

{

private:

string healthInsurance;

double lifeInsurance;

int vacation;

public:

Benefit(); //default constructor

Benefit(string health, double life, int vaca); //multi-arg constructor

void displayBenefits();

string getHealthInsurance();

void setHealthInsurance(string healthIns);

double getLifeInsurance();

void setLifeInsurance(double lifeIns);

int getVacation();

void setVacation(int vaca);

};

#endif

===============================================================================

//Benefit.cpp

#include <iostream>

#include <iomanip>

#include <string>

#include "Benefit.h"

Benefit::Benefit() //default constructor

{

healthInsurance = "Not Given";

lifeInsurance = 0.0;

vacation = 0;

}

Benefit::Benefit(string health, double life, int vaca) //multi-arg constructor

{

healthInsurance = health;

lifeInsurance = life;

vacation = vaca;

}

void Benefit::displayBenefits() //need to figure out how to right justify values.

{

cout << " Benefit Information" << endl;

cout << "____________________________________________" << endl;

cout << "Health Insurance: " << healthInsurance << endl;

cout << "Life Insurance: $" << setprecision(2) << showpoint << fixed << lifeInsurance << endl;

cout << "Vacation: " << vacation << " days" << endl;

}

string Benefit::getHealthInsurance()

{

return healthInsurance;

}

void Benefit::setHealthInsurance(string healthIns)

{

healthInsurance = healthIns;

}

double Benefit::getLifeInsurance()

{

return lifeInsurance;

}

void Benefit::setLifeInsurance(double lifeIns)

{

lifeInsurance = lifeIns;

}

int Benefit::getVacation()

{

return vacation;

}

void Benefit::setVacation(int vaca)

{

vacation = vaca;

}

===================================================================================

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote