Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THIS IS A C++ Program QUESTION!!! DO NOT ANSWER IN JAVA otherwise answer will be downvoted!!! Thank you Module 9 Question 2 (Payroll System Modification)

THIS IS A C++ Program QUESTION!!! DO NOT ANSWER IN JAVA otherwise answer will be downvoted!!!

Thank you

Module 9

Question 2

(Payroll System Modification) Modify the payroll system discussed in the class. You are now required to include private instance variable birthDate in class Employee. Use class Date we have discussed in previous modules, Assume that payroll is processed once per month. Create an array of Employee variables to store references to the various employee objects. In a loop, calculate the payroll for each Employee (polymorphically), and add a $100.00 bonus to the persons payroll amount if the current month is the month in which the Employees birthday occurs.

QUESTION- Change the Hourly rate of the Hourly Employee and give 10% increase in hourly rate

PROG32.cpp: PLEASE EDIT THIS PROGRAM AS SAID IN THE QUESTION

#include

#include

#include

#include

#include "Employee.h"

#include "HourlyEmployee.h"

#include "SalariedEmployee.h"

#include "CommissionEmployee.h"

#include "BasePlusCommissionEmployee.h"

using namespace std;

int main()

{

vector < Employee * > employees( 4 );

// initialize vector with various kinds of Employees

employees[ 0 ] = new SalariedEmployee("John", "Smith", "111-11-1111", 800 );

employees[ 1 ] = new CommissionEmployee("Sue", "Jones","333-33-3333", 10000, .06 );

employees[ 2 ] = new HourlyEmployee("John", "Charles", "111-11-1111", 26, 80 );

employees[ 3 ] = new BasePlusCommissionEmployee("Bob", "Lewis", "444-44-4444", 5000, .04, 300 );

// polymorphically process each element in vector employees

for ( Employee *employeePtr : employees )

{

employeePtr->print(); // output employee information

cout << endl;

// get the basePlusCommission Employee to provide a raise

BasePlusCommissionEmployee *derivedPtr = dynamic_cast < BasePlusCommissionEmployee * >( employeePtr );

// determine whether element points to a BasePlusCommissionEmployee

if ( derivedPtr != nullptr ) // true for "is a" relationship

{

double oldBaseSalary = derivedPtr->getBaseSalary(); // get the old salary

cout << "old base salary: $" << oldBaseSalary << endl; //print old salary

derivedPtr->setBaseSalary( 1.10 * oldBaseSalary ); // provide a 10% raise

cout << "new base salary with 10% increase is: $" << derivedPtr->getBaseSalary() << endl; // get the new salary

} // end if

cout << "earned $" << employeePtr->earnings() << " ";

// downcast pointer

//@ STUDENT TO DO : Change the Hourly rate of the Hourly Employee and give 10% increase in hourly rate

}

}

********************************************************************************************************************************

HourlyEmployee.cpp

#include

using std::cout;

using std::endl;

#include "HourlyEmployee.h" // Employee class definition

HourlyEmployee::HourlyEmployee( const string &first,

const string &last, const string &socialSecurityNumber,

double hourlyWage, double hoursWorked )

: Employee( first, last, socialSecurityNumber )

{

setWage( hourlyWage );

setHours( hoursWorked );

} // end HourlyEmployee constructor

// set hourly worker's wage

void HourlyEmployee::setWage( double wageAmount )

{

wage = wageAmount < 0.0 ? 0.0 : wageAmount;

} // end function setWage

// set hourly worker's hours worked

void HourlyEmployee::setHours( double hoursWorked )

{

hours = ( hoursWorked >= 0.0 && hoursWorked <= 168.0 ) ?

hoursWorked : 0.0;

} // end function setHours

// return hours worked

double HourlyEmployee::getHours() const

{

return hours;

} // end function getHours

// return wage

double HourlyEmployee::getWage() const

{

return wage;

} // end function getWage

// get hourly worker's pay

double HourlyEmployee::earnings() const

{

if ( hours <= 40 ) // no overtime

return wage * hours;

else // overtime is paid at wage * 1.5

return 40 * wage + ( hours - 40 ) * wage * 1.5;

} // end function earnings

// print hourly worker's information

void HourlyEmployee::print() const

{

cout << " hourly employee: ";

Employee::print(); // code reuse

} // end function print

********************************************************************************************************************************

HourlyEmployee.h

// Fig. 10.27: hourly.h

// HourlyEmployee class definition.

#ifndef HOURLY_H

#define HOURLY_H

#include "employee.h" // Employee class definition

class HourlyEmployee : public Employee {

public:

HourlyEmployee( const string &, const string &, const string &, double = 0.0, double = 0.0);

void setWage( double );

double getWage() const;

void setHours( double );

double getHours() const;

virtual double earnings() const;

virtual void print() const;

private:

double wage; // wage per hour

double hours; // hours worked for week

}; // end class HourlyEmployee

#endif // HOURLY_H

*****************************************************************

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

Lab Manual For Database Development

Authors: Rachelle Reese

1st Custom Edition

1256741736, 978-1256741732

More Books

Students also viewed these Databases questions