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

on microsoft visual studio C++ Scenario/Summary The objective of the lab is to t

ID: 3849157 • Letter: O

Question

on microsoft visual studio C++

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.

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.

Benefit Employee healthinsurance string #firstName string -lifeinsurance double #lastName string vacation int #gender char +Benefit #dependents int +Benefit (in hins String, in lins double, in vac: nt #annual salary double display Benefits Void #benefit Benefit static numEmployees int 30 +Employee() +Employee (in fname string, in Iname string, in gen char, in dep int, in benefits Benefit) static getNumEmployees nt +Calculate Pay() double display Employee Void Salaried MIN MANAGEMENT LEVEL int 0 MAX MANAGEMENT LEVEL int 3 BONUS PERCENT double 10 management eve nt +Salaried +Salaried(in fname string, in Iname string, in gen char, in dep int, in sal double, in ben Benefit, in manLevel int) +Salaried in sal double, in manLevel nt +CalculatePay() double +displayEmployee() void Hour MIN WAGE double 10 MAX WAGE double 75 MIN HOURS double 0 -MAX HOURS: double 50 -wage double -hours double category: string +Hour +Hourly(in w double, in hours double, in category: string age +Hourly n fname string, in Iname string, in gen char, in dep int, in age double n hours double, in ben Benefit, in category: string +Calculate Pay() double display Employee Void

Explanation / Answer

//main.cpp
#include "Benefits.h"
#include "Employee.h"
#include "Salaried.h"
#include "Hourly.h"
#include <iostream>
#include <string>
#endif

using namespace std;

int main(int argc, char *argv[]) {
    Benefits benefit1("PPO", 100, 200);
    Benefits benefit2("PPO", 5, 17); // can this be removed?
    Employee e1;
    Salaried s1(50000, 3);
  
  
    cout << "Welcome to your first Object-Oriented Program Employee Class 247C, Week 5 Lab ";
    cout << "Last name ";
    /*
    // Employee #1 User Input
    e1.setFirstName(" ");
    e1.setLastName(" ");
    e1.setGender(0);
    e1.setDependents(" ");
    e1.setAnnualSalary(" ");
    e1.benefit.setHealthInsurance(" ");
    e1.benefit.setLifeInsurance(0);
    e1.benefit.setVacation(0);
  
    e1.displayEmployee();
   
    // Salaried Employee
  
    s1.setFirstName("   ");
    s1.setLastName(" ");
    s1.setGender(' ');
    s1.setDependents(" ");
    s1.benefit.setHealthInsurance(" ");
    s1.benefit.setLifeInsurance(' ');
    s1.benefit.setVacation(' ');
    s1.calculatePay();
    s1.displayEmployee();
    */
    // Hourly Object
    Hourly h1("James", "Bond", 'M', 0, 40, 50, benefit2, "part-time");
    h1.displayEmployee();
  
    Employee::getNumEmployees();
    cout << "The end of the CIS 247C Week 5 iLab ";
  
} // end of main

============================================
//Salaried.cpp
#include <iostream>
#include <string>
#include <iomanip>
#include "Salaried.h"
#include "Employee.h"
#include <random>

using namespace std;


Salaried::Salaried(): MIN_MANAGEMENT_LEVEL(0), MAX_MANAGEMENT_LEVEL(3), BONUS_PERCENT(.1)
{
  
}
Salaried::~Salaried(){}

Salaried::Salaried(string fname, string lname, char gen, int dep, double sal, Benefits ben, int manLevel) : MIN_MANAGEMENT_LEVEL(0),MAX_MANAGEMENT_LEVEL(3), BONUS_PERCENT(.1)
{
  
}

Salaried::Salaried(double sal, int manLevel) : MIN_MANAGEMENT_LEVEL(0),MAX_MANAGEMENT_LEVEL(3), BONUS_PERCENT(.1)
{
    annualSalary = sal;
    managementLevel = manLevel;
}

void Salaried::setManagementLevel(int manLevel) {
   if (manLevel >= MIN_MANAGEMENT_LEVEL && manLevel <= MAX_MANAGEMENT_LEVEL){
        managementLevel = 1;
        managementLevel = manLevel;
    } else {
        manLevel = 2;
        managementLevel = manLevel;
    }
}

double Salaried::calculatePay(){
    int BONUS_PERCENT = annualSalary * (managementLevel * .1);
    return BONUS_PERCENT;

}


void Salaried::displayEmployee(){
    Employee::displayEmployee();
    cout << "Annual Salary: " << setprecision(2) << showpoint << fixed << annualSalary << " ";
    cout << "Weekly Salary: " << calculatePay() << " ";
    cout << " ";
  
    //**** Need to add annual and weekly salary with bonus added to it
    cout << " Salaried Employee ";
    cout << "Management Level: " << managementLevel << " ";
}
=================================================================
//Salaried.h
#include "Employee.h"
#include "Benefits.h"
#include <string>
#include <iostream>
#include <stdio.h>

using namespace std;

class Salaried : public Employee {
private:
    int managementLevel;
    const int MIN_MANAGEMENT_LEVEL;
    const int MAX_MANAGEMENT_LEVEL;
    const int BONUS_PERCENT;
  
public:
    Salaried();
    Salaried(string fname, string lname, char gen, int dep, double sal, Benefits benefit1, int manLevel);
    Salaried(double sal, int manLevel);
    ~Salaried();
  
    double calculatePay();
    void setManagementLevel(int manLevel);
    void displayEmployee();
};
#endif

============================================================
//Hourly.cpp
#include "Hourly.h"
#include "Employee.h"
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

Hourly::Hourly() : MIN_HOURS(0), MAX_HOURS(50), MIN_WAGE(10), MAX_WAGE(75)
{
  
}

Hourly::~Hourly(){}

Hourly::Hourly(double wage, double hours, string category) : MIN_HOURS(0), MAX_HOURS(50), MIN_WAGE(10), MAX_WAGE(75)
{
    /*if ((category == "temp") || (category == "part time") || (category == "full time")){
        cout << category;
    } else {
        cout << "Unknown";
    }*/

}

Hourly::Hourly(string fname, string lname, char gen, int dep, double _wage, double _hours, Benefits ben, string _category) : MIN_HOURS(0), MAX_HOURS(50), MIN_WAGE(10), MAX_WAGE(75)
{
    firstName = fname;
    lastName = lname;
    gender[0] = gen;
    dependents = dep;
    wage = _wage;
    hours = _hours;
    benefit = ben;
    if ((category == "temp") || (category == "part time") || (category == "full time")){
        category = _category;
    } else {
        cout << "Unknown";
    }

}

double Hourly::calculatePay(){
    if (hours > MIN_HOURS && hours < MAX_HOURS){
        if (wage >= MIN_WAGE && wage <= MAX_WAGE){
            wage = hours * wage;
          
        } else {
            cout << "Invalid wage";
        }
    } else {
        cout << "Invalid range of hours";
    }
  
    return wage;
}

void Hourly::displayEmployee(){
    Employee::displayEmployee();
    cout << "Annual Salary: " << setprecision(2) << showpoint << fixed << annualSalary << " ";
    cout << "Weekly Salary: " << calculatePay() << " ";
    cout << " ";

    cout << " Hourly Employee ";
    cout << "Category: " << category <<" ";
    cout << "Wage: " << wage << " ";
    cout << "Hours: " << hours << " ";
}
==========================================================================
//Hourly.h
#include "Employee.h"
#include "Benefits.h"
#include <string>
#include <iostream>
#include <stdio.h>


using namespace std;

class Hourly : public Employee{
  
private:
    const double MIN_WAGE;
    const double MAX_WAGE;
    const double MIN_HOURS;
    const double MAX_HOURS;
    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, Benefits ben, string _category);
    ~Hourly();
  
    double calculatePay();
    void displayEmployee();
  
};


#endif
=====================================================
//Employee.cpp
#include "Employee.h"
#include "Benefits.h"
#include "Salaried.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <sstream>
#endif

using namespace std;
Benefits benefit;
Benefits benefit1("PPO", 100, 200);
Employee::Employee()
{
    this -> firstName="not given";
    strncpy(gender, "U", 1);
    this -> dependents=0;
    this -> annualSalary=20000;
    numEmployees++;
} // end of default constructor

int Employee::numEmployees = 0;

Employee::Employee(string first, string last, char gen, int dep, double salary, Benefits benefit1 ){
    firstName = first;
    lastName = last;
    gender[0] = gen;
    dependents = dep;
    annualSalary = salary;
    numEmployees++;
}

//deconstructor
Employee::~Employee(){
    numEmployees--;
}

// Public Access Method Definitions

void Employee::setFirstName(string first){
  
    cout << "Please enter your first name: ";
    getline(cin, firstName);
  
}
string Employee::getFirstName(){
    return this -> firstName;
}

void Employee::setLastName(string last){
  
    cout << "Please enter your last name: ";
    getline(cin, lastName);
}
string Employee::getLastName(){
  
    return this -> lastName;
}
void Employee::setGender(char gen){
  
    cout << "Please enter your gender: ";
    cin >> gender;
}

char Employee::getGender(){
  
    return gender[0];
}

void Employee::setDependents(int dep){
  
    cout << "Please enter your Dependents: ";
    cin >> dependents;
}

void Employee::setDependents(string dep){
    cout << "Please enter your Dependents: ";
    cin >> dependents;
}

int Employee::getDependents(){
  
    return dependents;
}
void Employee::setAnnualSalary(double salary){
  
    cout << "Please enter your Annual Salary: ";
    cin >> annualSalary;
}

void Employee::setAnnualSalary(string salary){
    ostringstream s;
    cout << "Please enter your Annual Salary: ";
    cin >> annualSalary;
}

double Employee::getAnnualSalary(){
  
    return annualSalary;
}
double Employee::calculatePay(){
  
    return annualSalary/52;
  
}

int Employee::getNumEmployees(){
    cout << " --- Number of Employee Object(s) Created---- ";
    cout << "Number of Employees: " << numEmployees << " ";
    cout << " ";
  
    return 0;
}

void Employee::displayEmployee(){
    cout << " Employee Information ";
    cout << "------------------------------------------------- ";
    cout << "Name: " << firstName << " " << lastName + " ";
    cout << "Gender: " << gender << " ";
    cout << "Dependents: " << dependents << " ";
    benefit.displayBenefits();
    }
========================================================================
//Employee.h
#include<string>
#include<iostream>
#include "Benefits.h"


using namespace std;

class Employee
{
public:
  
    Employee();
    Employee(string first, string last, char gen, int dep, double salary, Benefits benefit1);
    ~Employee();
  
    // public access methods
    double calculatePay();
    void displayEmployee();
    string getFirstName();
    void setFirstName(string first);
    string getLastName();
    void setLastName(string last);
    char getGender();
    void setGender(const char gen);
    int getDependents();
    void setDependents(int dep);
    void setDependents(string);
    void setAnnualSalary(string);
    double getAnnualSalary();
    void setAnnualSalary(double salary);
    static int getNumEmployees();
    Benefits benefit;
  
    // private members
protected:
    string firstName;
    string lastName;
    char gender[1];
    int dependents;
    double annualSalary;
    static int numEmployees;
}; // End of Employee class
#endif
==================================================================
//Benefits.cpp
#include "Benefits.h"
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

Benefits::Benefits()
{
    this -> healthinsurance="not given";
    this -> lifeinsurance=0;
    this -> vacation=0;
}

Benefits::Benefits(string health, double life, int vac){
    healthinsurance = health;
    lifeinsurance = life;
    vacation = vac;
}

Benefits::~Benefits(){}

void Benefits::setHealthInsurance(string hins){
    cout << "Please enter your Health Insurance: ";
    cin >> healthinsurance;
}

string Benefits::getHealthInsurance(){
    return healthinsurance;
}

void Benefits::setLifeInsurance(double lifeIns){
    cout << "Please enter your Life Insurance: ";
    cin >> lifeinsurance;
}

double Benefits::getLifeInsurance(){
    return lifeinsurance;
}

void Benefits::setVacation(int vaca){
    cout << "Please enter your Vacation Days: ";
    cin >> vacation;
}

int Benefits::getVacation(){
    return vacation;
}

void Benefits::displayBenefits(){
    cout << "Benefits Information ";
    cout << "------------------------------------------------- ";
    cout << "Health Insurance: " << healthinsurance << " ";
    cout << "Life Insurance: " << lifeinsurance<< " ";
    cout << "Vacation: " << vacation << " days ";
}
==================================================
//Benefits.h
#include<string>
#include<iostream>
#include<stdio.h>

using namespace std;

class Benefits
{
public:
    Benefits();
    Benefits(string health, double life, int vac);
    ~Benefits();
  
    // public access methods
    void displayBenefits();
    string getHealthInsurance();
    void setHealthInsurance(string hins);
    double getLifeInsurance();
    void setLifeInsurance(double lifeIns);
    int getVacation();
    void setVacation(int vaca);
  
    // private members
private:
    string healthinsurance;
    double lifeinsurance;
    int vacation;
};

#endif