Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

on c++ microsoft visual studio Scenario/Summary We have two separate goals this week: We are going to create an abstract Employee class and two pure

on c++ microsoft visual studio

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.

image text in transcribed

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:

image text in transcribed

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: image text in transcribed

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

Partial Sample Output: image text in transcribed

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.

image text in transcribed

week 5

#include

#include

#include

#include

using namespace std;

class Benefit {

private:

string healthinsurance;

double lifeinsurance;

int vacation;

public:

Benefit() {

healthinsurance = "";

lifeinsurance = 0;

vacation = 0;

}

Benefit(string health, double life, int vaca) {

healthinsurance = health;

lifeinsurance = life;

vacation = vaca;

}

//method that displays employee information

void displayBenefits()

{

cout

cout

cout

cout

cout

}

void setHealthInsurance(string hins) {

healthinsurance = hins;

}

string getHealthInsurance() {

return healthinsurance;

}

void setLifeInsurance(double lifeins) {

lifeinsurance = lifeins;

}

double getLifeInsurance() {

return lifeinsurance;

}

void setVacation(int vaca) {

vacation = vaca;

}

int getVacation() {

return vacation;

}

};

class Employee

{

private:

static int numEmployees;

//member variables of Employee class

protected:

string firstName;

string lastName;

char gender;

int dependents;

double annualSalary;

Benefit benefit;

public:

//default constructor

Employee()

{

//set the member variables to default values

firstName = "not given";

lastName = "not given";

gender = 'U';

dependents = 0;

annualSalary = 20000;

//Incrementing number of employees

numEmployees += 1;

}

//constructor with parameters

Employee(string first, string last, char gen, int dep, double salary, Benefit benef)

{

//set the member variables to values passed

firstName = first;

lastName = last;

gender = gen;

dependents = dep;

annualSalary = salary;

//Incrementing number of employees

numEmployees += 1;

benefit = benef;

}

//getter methods

//method that gets firstName

string getfirstName()

{

return firstName;

}

//method that gets lastName

string getlastName()

{

return lastName;

}

//method that gets gender

char getGender()

{

return gender;

}

//method that gets dependents

int getdependents()

{

return dependents;

}

//method that gets annual salary

double getannualSalary()

{

return annualSalary;

}

//setter methods

//method that sets firstname

void setfirstName(string first)

{

firstName = first;

}

//method that sets lastname

void setlastName(string last)

{

lastName = last;

}

//method that sets gender

void setGender(char gen)

{

gender = gen;

}

//method that sets dependents

void setdependents(int dep)

{

dependents = dep;

}

//method that sets annual salary

void setannualSalary(double salary)

{

annualSalary = salary;

}

//Overloaded method that sets dependents

void setdependents(string dep)

{

dependents = stoi(dep);

}

//Overloaded method that sets annual salary

void setannualSalary(string salary)

{

annualSalary = stod(salary);

}

//method that calculates weekly pay

double calculatePay()

{

//calculate and return weekly pay

return annualSalary / 52;

}

//Static method

static int getNumEmployees()

{

//Return number of employee objects created

return numEmployees;

}

Benefit getBenefit() {

return benefit;

}

void setBenefit(Benefit ben) {

benefit = ben;

}

//method that displays employee information

void displayEmployee()

{

cout

cout

cout

cout

cout

cout

cout

cout

benefit.displayBenefits();

}

};

int Employee::numEmployees = 0;

class Salaried: public Employee

{

private:

int managementLevel;

const int MIN_MANAGEMENT_LEVEL;

const int MAX_MANAGEMENT_LEVEL;

const double BONUS_PERCENT;

public:

Salaried(); //Default constructor

Salaried(string fname, string lname, char gen, int dep, double sal, Benefit ben, int manLevel); //Overloaded constructor with all paramters passed

Salaried(double sal, int manLevel);//Overloaded constructor with partial paramters passed

double calculatePay(); //Function inherited from the Parent Employee class

void displayEmployee(); //display Employee details specific to Employee and Salaried objects

};

Salaried::Salaried():Employee(), MIN_MANAGEMENT_LEVEL(0),MAX_MANAGEMENT_LEVEL(3),BONUS_PERCENT(10) //Default constructor of salaried class which is calling parent class default constructor and initializing constant private variables

{

managementLevel = MIN_MANAGEMENT_LEVEL;

}

Salaried::Salaried(string fname, string lname, char gen, int dep, double sal, Benefit ben, int manLevel):Employee(fname, lname, gen, dep, sal, ben), MIN_MANAGEMENT_LEVEL(0),MAX_MANAGEMENT_LEVEL(3),BONUS_PERCENT(10)

//Overloaded constructor of salaried class that is calling parent class constructor and initializing all private constant variables

{

if (manLevel >= MIN_MANAGEMENT_LEVEL && manLevel

managementLevel = manLevel; //set managementLevel as entered

else if (manLevel

managementLevel = MIN_MANAGEMENT_LEVEL; //Initialize dependents to Min managementLevel

else if (manLevel > MAX_MANAGEMENT_LEVEL) //If value is greater than max managementLevel

managementLevel = MAX_MANAGEMENT_LEVEL; //Initialize dependents to Max managementLevels

}

Salaried::Salaried(double sal, int manLevel):Employee(), MIN_MANAGEMENT_LEVEL(0),MAX_MANAGEMENT_LEVEL(3),BONUS_PERCENT(10)

//Overloaded constructor of salaried class paramters that is calling parent class default constructor and initializing all private constant variables

{

if (manLevel >= MIN_MANAGEMENT_LEVEL && manLevel

managementLevel = manLevel; //set managementLevel as entered

else if (manLevel

managementLevel = MIN_MANAGEMENT_LEVEL; //Initialize dependents to Min managementLevel

else if (manLevel > MAX_MANAGEMENT_LEVEL) //If value is greater than max managementLevel

managementLevel = MAX_MANAGEMENT_LEVEL; //Initialize dependents to Max managementLevels

this->annualSalary = sal;

}

double Salaried::calculatePay() //Function calculatePay is overridden and gives a different meaning for Salaried class

{

double actualBonusPercentage = managementLevel * BONUS_PERCENT / 100; //Bonus percent = management leve multiply by 0.1 which is a constant here

double BonusAmount = actualBonusPercentage * this->annualSalary; //Total yearly bonus amount = bonus percentage multiply by annual salary

this->annualSalary = this->annualSalary + BonusAmount;

return (this->annualSalary) / 52; //weekly pay should be calculated like total annual salary plus bonus amount and here we are assuming 52 weeks in an year

}

void Salaried::displayEmployee() //display Employee details specific to Employee and Salaried objects

{

cout

cout

cout

cout

cout

cout

cout

cout

benefit.displayBenefits();

cout

cout

}

class Hourly: public Employee //Hourly class is inherited from employee class and inheritance level is set as public here

{

private:

double wage;

double hours;

string category;

const int MIN_WAGE; //Default value for MIN WAGE LEVEL

const int MAX_WAGE; //Default value for MAX WAGE LEVEL

const int MIN_HOUR; //Default value for MIN HOUR LEVEL

const int MAX_HOUR; //Default value for MAX HOUR LEVEL

public:

Hourly(); //Default constructor of Hourly class

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

};

double::Hourly::calculatePay()//Function calculatePay is overridden and gives a different meaning for Hourly class

{

return this->hours * this->wage; //Hourly employee pay would be equal to hours worked * hourly pay

}

Hourly::Hourly():Employee(),MIN_WAGE(10),MAX_WAGE(75),MIN_HOUR(0),MAX_HOUR(50)

{

wage = MIN_WAGE; //Initialize wage to default min wage value

hours = MIN_HOUR; //Initialize hour to default min hour value

category = "Unknown"; //Initialize category to default value

this->annualSalary = calculatePay()*50;

}

Hourly::Hourly(string fname, string lname, char gen, int dep, double wage, double hours, Benefit ben, string category):Employee(fname,lname, gen, dep, 0.0,ben),MIN_WAGE(10),MAX_WAGE(75),MIN_HOUR(0),MAX_HOUR(50)

//Overloaded constructor of Hourly class. The constructor will be calling overloaded constructor of parent class

{

double wge = wage;

if (wge >= MIN_WAGE && wge

this->wage = wge; //set WAGE as entered

else if (wge

this->wage = MIN_WAGE; //Initialize dependents to Min WAGE

else if (wge > MAX_WAGE) //If value is greater than max WAGE

this->wage = MAX_WAGE; //Initialize dependents to Max WAGE

double hour = hours;

if (hour >= MIN_HOUR && hour

this->hours = hour; //set Hour as entered

else if (hour

this->hours = MIN_HOUR; //Initialize dependents to Min Hour

else if (hour > MAX_HOUR) //If value is greater than max Hour

this->hours = MAX_HOUR; //Initialize dependents to Max Hour

if ( category == "temporary" || category == "part time" || category == "full time" ) //If value lies between min and max Hour

this->category = category; //set category as entered

else

this->category = "Unknown"; //set Category to unknown otherwise

this->annualSalary = calculatePay()*50;

}

Hourly::Hourly(double wage, double hours, string category):Employee(),MIN_WAGE(10),MAX_WAGE(75),MIN_HOUR(0),MAX_HOUR(50)

{

double wge = wage;

if (wge >= MIN_WAGE && wge

this->wage = wge; //set WAGE as entered

else if (wge

this->wage = MIN_WAGE; //Initialize dependents to Min WAGE

else if (wge > MAX_WAGE) //If value is greater than max WAGE

this->wage = MAX_WAGE; //Initialize dependents to Max WAGE

double hour = hours;

if (hour >= MIN_HOUR && hour

this->hours = hour; //set Hour as entered

else if (hour

this->hours = MIN_HOUR; //Initialize dependents to Min Hour

else if (hour > MAX_HOUR) //If value is greater than max Hour

this->hours = MAX_HOUR; //Initialize dependents to Max Hour

if ( category == "temporary" || category == "part time" || category == "full time" ) //If value lies between min and max Hour

this->category = category; //set category as entered

else

this->category = "Unknown"; //set Category to unknown otherwise

this->annualSalary = calculatePay()*50;

}

void Hourly::displayEmployee() //Function displayEmployee is overridden and display Employee specific plus Hourly specific information

{

cout

cout

cout

cout

cout

cout

cout

cout

benefit.displayBenefits();

cout

coutcategory

couthours

coutwage

}

int main()

{

//display banner

cout

cout

cout

//declare object for Employee

Employee emp1;

string fname, lname;

string gender, dependents, salstr, healthins;

double sal, lifeinsur;

int vacation;

//prompt and read employee information

cout

cin >> fname;

cout

cin >> lname;

cout

cin >> gender;

cout

cin >> dependents;

cout

cin >> salstr;

cout

cin >> healthins;

cout

cin >> lifeinsur;

cout

cin >> vacation;

Benefit bene(healthins,lifeinsur,vacation);

emp1.setBenefit(bene);

//set the employee information using setter methodds

emp1.setfirstName(fname);

emp1.setlastName(lname);

emp1.setGender(gender[0]);

/* Calling the new overloaded setters */

emp1.setdependents(dependents);

emp1.setannualSalary(salstr);

//display employee info

emp1.displayEmployee();

//Calling and displaying number of employee objects created

cout

cout

Benefit ben("HMO", 100, 16);

//create second object for Employee

//pass employee information as parameters

Salaried emp2 = Salaried("Jackie", "Chan", 'M', 1, 50000, ben,3);

cout

//display employee info

emp2.displayEmployee();

//Calling and displaying number of employee objects created

cout

cout

Benefit ben22("PPO", 5, 17);

//create second object for Employee

//pass employee information as parameters

Hourly emp3 = Hourly("James", "Bond", 'M', 0, 40, 50,ben22,"");

cout

//display employee info

emp3 .displayEmployee();

//Calling and displaying number of employee objects created

cout

cout

cout

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 2 Lnai 6322

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215882X, 978-3642158827

More Books

Students also viewed these Databases questions

Question

Design a health and safety policy.

Answered: 1 week ago