Question & Answer: We have two separate goals this week:…..

on c++

Scenario/Summary

We have two separate goals this week:

We are going to create an abstract Employee class and two pure virtual functions – calculatePay() and displayEmployee(). The abstract Employee class will prevent a programmer from creating an object based on Employee, however, a pointer can still be created. Objects based on Salaried and Hourly will be allowed. The pure virtual function calculatePay() in Employee will force the child classes to implement calculatePay(). The other pure virtual function displayEmployee() in Employee will force the child classes to implement displayEmployee().

We are going to implement Polymorphism and dynamic binding in this Lab.

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 it into a Word document.

Zip the project folder in the Microsoft Visual Studio.

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 in the updated UML diagram that the Employee class is designated as abstract by having the class name Employee italicized. Also, the calculatePay method is italicized, which means that it is a pure virtual function and needs to be implemented in the derived classes. In addition, make displayEmployee() method a pure virtual function as well.

STEP 2: Create the Project

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

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

STEP 3: Modify the Employee Class

Define calculatePay() as a pure virtual function.

Define displayEmployee() as a pure virtual function.

When class Employee contains two pure virtual functions, it becomes an abstract class.

STEP 4: Create Generalized Input Methods

Reuse method getInput() from the previous Lab to prompt the user to enter Employee information.

STEP 5: Modify the Main Method

Create two employee pointers with:

The first employee pointer refers to a salaried employee and the second employee pointer refers to a hourly employee.

Prompt the user to enter information for these two pointers and display the calculated result.

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

Partial Sample Output:

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

Partial Sample Output:

STEP 6: 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 a complete sample program output for your reference.

Expert Answer

 

#pragma once

#include “Employee.h”

#ifndef BENEFIT_H
#define BENEFIT_H
using namespace std;
#include<string>

//Benefit class
class Benefit {

private:
//healthInsurance and lifeInsurance varibales
string healthInsurance;
double lifeInsurance;
int vacation;

public:
//constructor
Benefit();

//constructor with parameters
Benefit(string in_hins, double in_lins, int in_vac);
void displayBenefit();

};

#endif

#include “Benefit.h”
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

//Default constructor
Benefit::Benefit() {
cout << “Default constructor”;
}

//Parameterized constructor

Benefit::Benefit(string in_hins, double in_lins, int in_vac) {

healthInsurance = in_hins;
lifeInsurance = in_lins;
vacation = in_vac;
}

void Benefit::displayBenefit() {

cout << healthInsurance;
}

//Hourly.h
#pragma once
const double MIN_WAGE = 10;
const double MAX_WAGE = 75;
const double MIN_HOURS = 0;
const double MAX_HOURS = 50;

#include “Employee.h”
#include<string>
#ifndef HOURLY_H
#define HOURLY_H
using namespace std;

class Hourly : public Employee
{
private:
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();
//setters and getters
double getWage();
void setWage(double wge);
double getHours();
void setHours(double hrs);
string getCategory();
void setCategory(string cat);
double getAnnualSalary();
void setAnnualSalary(double wage, double hours); //added to override set annual salary from Employee class.
};

#endif

//Hourly.cpp

#include <iostream>
#include <iomanip>
#include <string>
#include “Hourly.h”
#include “Employee.h”
#include “Benefit.h”
using namespace std;
//Hourly class with default constructor
Hourly::Hourly()
{
wage = 0;
hours = 0;
category = “Unknown”;
}

//Hourly class with parameter constructor

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)
{
wage = wge;
hours = hrs;
category = cat;
}

double Hourly::calculatePay() //returns weekly pay calculated from hourly wage and hours worked.
{
return wage * hours;
}

void Hourly::displayEmployee()
{
cout << “nEmployee Information” << endl;
cout << “________________________________________________” << endl;
cout << “Name: ” << firstName << ” ” << lastName << endl;
cout << “Gender: ” << gender << endl;
cout << “Dependents: ” << dependents << endl;
setAnnualSalary(wage, hours);
cout << “Annual Salary: $” << fixed << setprecision(2) << annualSalary << endl;
cout << “Weekly Salary: $” << fixed << setprecision(2) << calculatePay() << endl;
cout << “nHourly Employee” << endl;
cout << “Category: ” << category << endl;
cout << “Wage: ” << wage << endl;
cout << “Hours: ” << hours << endl;
}

double Hourly::getWage()
{
return wage;
}

void Hourly::setWage(double wge)
{
wage = wge;
}

double Hourly::getHours()
{
return hours;
}

void Hourly::setHours(double hrs)
{
hours = hrs;
}

string Hourly::getCategory()
{
return category;
}

void Hourly::setCategory(string cat)
{
category = cat;
}

double Hourly::getAnnualSalary()
{
return annualSalary;
}

void Hourly::setAnnualSalary(double wage, double hours) //will need to update later
{
while ((wage < MIN_WAGE) || (wage > MAX_WAGE))
{
cout << “Invalid Entry!!” << endl;
cout << “Valid range for wages: $10 to $75” << endl;
}

while ((hours < MIN_HOURS) || (hours > MAX_HOURS))
{
cout << “Invalid Entry!!” << endl;
cout << “Valid number of hours worked: 0 to 50” << endl;
}

annualSalary = wage * hours * 50;
}

#pragma once
//Employee.h

#ifndef EMPLOYEE_H //inclusion guard
#define EMPLOYEE_H
#include “Benefit.h”
using namespace std;
#include<string.h>
#include<iostream>
#include<cstdlib>

#include “stdafx.h”

//Employee class
class Employee
{

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

public: //member variables
string firstName;
string lastName;
char gender;
int dependents;
double annualSalary;
string healthInsurance;
double lifeInsurance;
int vacation;

Employee(void); //default constructor

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

Employee(string firstName, string lastName, char gen, int dep); //multi-arg constructor
virtual double calculatePay() = 0;
virtual void displayEmployee() = 0;

//setter and getter methods
string getFirstName();
void setFirstName(string first);
string getLastName();
void setLastName(string last);
char getGender();
void setGender(char gen);
int getDependents();
void setDependents(int dep);
double getAnnualSalary();
void setAnnualSalary(double salary);

void setHealthInsurance(string healthInsurance);
string getHealthInsurance();

void setlifeInsurance(double lifeInsurance);
double getlifeInsurance();

void setVacation(int vacation);
int getVacation();

};

#endif

//Employee.cpp

#include “Employee.h”
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

//Default constructor
Employee::Employee() {
}

//parameter constructor
Employee::Employee(string fname, string lname, char gen, int dep){
firstName = fname;
lastName = lname;
gender = gen;
dependents = dep;
}

double Employee::calculatePay() {
return 1000;
}
//methods
void Employee::displayEmployee() {

}
//setter and getter methods
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;

}

double Employee:: getAnnualSalary() {
return annualSalary;

}
void Employee::setAnnualSalary(double salary) {
salary = salary;
}

void Employee::setHealthInsurance(string healthInsurance) {
healthInsurance = healthInsurance;
}

string Employee::getHealthInsurance() {
return healthInsurance;
}

void Employee::setlifeInsurance(double lifeInsurance) {
lifeInsurance = lifeInsurance;
}
double Employee::getlifeInsurance() {
return lifeInsurance;
}

void Employee::setVacation(int vacation) {
vacation = vacation;
}
int Employee::getVacation() {
return vacation;
}
//salaried.h

#pragma once
const int MIN_MANAGEMENT_LEVEL = 0;
const int MAX_MANAGEMENT_LEVEL = 3;
const double BONUS_PERCENT =10;

#include “Employee.h” //Is Employee.h neccessary????
#ifndef HOURLY_H
#define HOURLY_H
#include<string>
using namespace std;

//salaried class inherited from Employee
class Salaried : public Employee
{
private:
int managementLevel;
public:

//methods and constructors
Salaried();
Salaried(string in_fname, string in_lname, char in_gen, int in_dept, double in_sal, int in_manLevel);
Salaried(double in_sal, int in_manLevel);
double calculatePay();
void displayEmployee();
};

#endif

//salaried.cpp
#include<iostream>
#include<string>
#include “Salaried.h”

#include “Benefit.h”

using namespace std;
Salaried::Salaried() {
cout << endl;
cout << “From default constructor” << endl;
cout << endl;
}
Salaried::Salaried(string in_fname, string in_lname, char in_gen, int in_dept, double in_sal, int in_manLevel) {

firstName = in_fname;
lastName = in_lname;
gender = in_gen;
dependents = in_dept;
annualSalary = in_sal;
//benefit = in_ben;
managementLevel = in_manLevel;

}

Salaried::Salaried(double in_sal, int in_manLevel) {
annualSalary = in_sal;
managementLevel = in_manLevel;

}

double Salaried::calculatePay() {
return 1000;
}
void Salaried::displayEmployee() {

}
// CIS247C_WK6_Lab_Employee.cpp : Defines the entry point for the console application.
//

#include “stdafx.h”

#include “Employee.h”
#include “Benefit.h”
#include “Salaried.h”
#include “Hourly.h”
#include “Employee.h”
using namespace std;

#include<string>
int main()
{

//employeelist object with pointer type
Employee *employeeList1 = new Salaried(10000, 3);

//employelist object with pointer type with parameters
Employee *employeeList2 = new Salaried(“Nana”, “Liu”, ‘F’, 2, 60000, 1500);

//Benefit object creation
Benefit benifit(“PPO”, 1.50, 21);

//Salaried class with two parameters
Employee *employeeList3 = new Salaried(5000, 1);

//Default constructor of the Benefit class
Benefit benifit1();

Salaried s();

//variable declaration
string firstName;
string lastName;
char gender;
int dependents;
double annualSalary;

string healthInsurance;
double lifeInsurance;
int vacation;

//Display statements for Input
cout << ” Welcome to object oriented Program – Employee Class CIS247C, Week 6 Lab Name: Prof.Nana Liu” << endl;
cout << “*********************Employee 1 **************************” << endl;
cout << endl;
cout << endl;
cout << “Please Enter your First Name : “;
cin >> firstName;
employeeList2->setFirstName(firstName);
cout << endl;

cout << “Please Enter your Last Name : “;
cin >> lastName;
employeeList2->setLastName(lastName);
cout << endl;

cout << “Please Enter your Gender : “;
cin >> gender;
employeeList2->setGender(gender);
cout << endl;

cout << “Please Enter your Dependents : “;
cin >> dependents;
employeeList2->setDependents(dependents);
cout << endl;

cout << “Please Enter your Annual Salary : “;
cin >> annualSalary;
employeeList2->setAnnualSalary(annualSalary);
cout << endl;

cout << “Please Enter your Health Insurance : “;
cin >> healthInsurance;
employeeList2->setHealthInsurance(healthInsurance);
cout << endl;

cout << “Please Enter your Life Insurance : “;
cin >> lifeInsurance;
employeeList2->setlifeInsurance(lifeInsurance);
cout << endl;

cout << “Please Enter your vacation : “;
cin >> vacation;
employeeList2->setVacation(vacation);
cout << endl;
//Display statements for output

cout << “Employee Information ” << endl;
cout << “______________________________________________________________” << endl;
cout << ” Name :” << employeeList2->getFirstName() << ” ” << employeeList2->getLastName()<< endl;
cout << ” Gender :” << employeeList2->getGender() <<endl;
cout << ” Dependents :” << employeeList2->getDependents() << endl;
cout << ” Annual Salary :” << employeeList2->getAnnualSalary() << endl;
cout << “Benifit Information ” << endl;
cout << “______________________________________________________________” << endl;
cout <<” Health Insurance :” << employeeList2->getHealthInsurance() << endl;
cout <<” Life Insurance :” << employeeList2->getlifeInsurance() << endl;
cout << ” Vacation :” << employeeList2->getVacation() << endl;

cout << “The end of the CIS247C Week6 iLab” << endl;
system(“pause”);
return 0;
}

Still stressed from student homework?
Get quality assistance from academic writers!