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

C++ STEP 1: Understand the UML Diagram The only change to the Employee class is

ID: 3843373 • Letter: C

Question

C++

STEP 1: Understand the UML Diagram

The only change to the Employee class is that there is a new attribute:

Notice that there is a "+" for this attribute, meaning that it is public. Make sure to examine the multi-arg constructor's signature!

Also, the dotted directed line between Employee and iEmployee specifies that the Employee class must implement the iEmployee abstract class, and thus provide an implementation for the calculatePay method.

Listen

STEP 2: Create the Project

You will want to use the Week 3 project as the starting point for the lab. To do this, you will want to create a new project by following these steps:

Create a new project and name it "CIS247C_WK4_Lab_LASTNAME".

Copy all the source files from the Week 3 project into the Week 4 project.

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

Listen

STEP 3: Modify the Employee Class

Using the UML Diagrams from Step 1, create the Benefit class. To get an idea of how to format displayBenefits, take a look at the output in Step 5.

Add a Benefit attribute to the Employee class.

Initialize the new Benefit attribute in both Employee constructors. Again, take note of the multi-arg constructors parameter list!

Create the iEmployee interface (abstract class in C++).

Modify the Employee class to call displayBenefit when displaying Employee information.

Listen

STEP 4: Modify the Main Method

Notice that the Employee class now has a public benefit object inside it. This means that you can access the set methods of the Benefit object with the following code:

As an example, to set the lifeInsurance attribute inside an Employee object called emp, we could execute the following code:

The steps required to modify the Main class are below. New steps are in bold.

Create an Employee object using the default constructor.

Prompt for and then set the first name, last name, and gender. Consider using your getInput method from Week 1 to obtain data from the user for this step as well as Step 3.

Prompt for and then set the dependents and annual salary using the overloaded setters that accept Strings.

Prompt for and set healthInsurance, lifeInsurance, and vacation.

Using your code from Week 1, display a divider that contains the string "Employee Information".

Display the Employee Information.

Display the number of employees created using getNumEmployees(). Remember to access getNumEmployees using the class name, not the Employee object.

Create a Benefit object called benefit1 using the multi-arg construction. Use any information you want for health insurance, life insurance, and vacation.

Create another Employee object and use the constructor to fill it with the following:
"Mary", "Noia", 'F', 5, 24000.0, benefit1

Using your code from Week 1, display a divider that contains the string "Employee Information".

Display the employee information.

Display the number of employees created using getNumEmployees(). Remember to access getNumEmployees using the class name, not the Employee object.

Listen

STEP 5: 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.

Listen

STEP 6: Screen Prints

Capture the Console output window and paste it into a Word document. The following is a sample screen print.

Listen

Employee +calculatePay) double Benefit healthinsurance string -lifeinsurance double vacation int +Benefit +Benefit in health :string, in life double, in vacation int) displayBenefits void get Healthlnsurance string +set HealthInsutance(in hins string) void getLifelnsurance double setLifeInsurance(in lifelns double Void getVacation nt setVacation (in vaca nt Void Employee firstName: String lastName string gender char dependents int annua Salary double static numEmployees int 0 +benefit Benefit +Employee() +Employee (in fname String, in Iname String, in gen: char, in dep int, in sal double) 1 calculatePay() double display Employee() void static getNumEmployees nt get FirstName string set FirstName (in name String Void get LastName String +setLast Name (in name: String) Void +get Gender char set Gender (in gen char void getDependents nt set Dependents(in dep int) void getAnnual Salary() double setAnnual Salary (in sal double Void setAnnual Sala n Sal Strin Void

Explanation / Answer

EmployeeTest.cpp

#include <iostream>
#include <iomanip>
#include <string>
#include "Employee.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.benefit.setHealthInsurance(healthInsurance);

   string lifeInsurance = GetInput("life insurance");
   employee1.benefit.setLifeInsurance(stod(lifeInsurance));

   string vacation = GetInput("vacation");
   employee1.benefit.setVacation(stoi(vacation));

   employee1.displayEmployee();

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

   //This section uses multi-arg constructor to set values for employee2 object.
   Benefit benefit1("Anthem", 15000.25, 48);
   Employee employee2("Mary", "Noia", 'F', 5, 24000.00, benefit1);

   DisplayDivider("Employee 2");
   employee2.displayEmployee();

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


   TerminateApplication();

return 0;
}

//functions defined from Basic UI week 1 lab.
void DisplayApplicationInformation()
{
   cout << "Welcome to the Employee Class Test Program." << endl;
   cout << "CIS247C, Week 4 Lab." << endl;
   cout << "Name: Steven Bennett" << endl;
   cout << "This program has been updated to include Benefit class and iEmployee abstract class." << 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;
}

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 << 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;
}

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


Employee.cpp

#include <iostream>
#include <iomanip>
#include <string>
#include "Employee.h"
#include "Benefit.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, double salary, Benefit ben) : benefit(ben) //constructor with arguments
{
   firstName = first;
   lastName = last;
   gender = gen;
   dependents = dep;
   annualSalary = salary;
   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.
}

int Employee::numEmployees = 0; //initialize static variable numEmployees to 0.
int Employee::getNumEmployees() //static member function
{
   return numEmployees;
}


Employee.h

#ifndef EMPLOYEE_H //inclusion guard
#define EMPLOYEE_H
#include "Benefit.h"
#include "iEmployee.h"
using namespace std;

class Employee : public iEmployee
{
private: //private attributes
   string firstName;
   string lastName;
   char gender;
   int dependents;
   double annualSalary;
   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, double salary, 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 benefit; //public benefit object allows access to Benefit methods in main.
};

#endif

iEmployee.h

#ifndef I_EMPLOYEE_H
#define I_EMPLOYEE_H
using namespace std;

class iEmployee
{
public:
   virtual double calculatePay() = 0;
};

#endif

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