Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include #include #include #include Employee.h #include HourlyEmployee.h #include SalariedEmployee.h #include CommissionEmployee.h #include BasePlusCommissionEmployee.h using namespace std; int main (
#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;
initialize vector with various kinds of Employees
employees new SalariedEmployeeJohn "Smith", ;
employees new CommissionEmployeeSue "Jones",";
employees new HourlyEmployeeJohn "Charles", ;
employees new BasePlusCommissionEmployeeBob "Lewis", ;
polymorphically process each element in vector employees
for Employee employeePtr : employees
employeePtrprint; output employee information
cout endl;
get the basePlusCommission Employee to provide a raise
BasePlusCommissionEmployee derivedPtr dynamiccast BasePlusCommissionEmployee employeePtr ;
determine whether element points to a BasePlusCommissionEmployee
if derivedPtr nullptr true for is a relationship
double oldBaseSalary derivedPtrgetBaseSalary; get the old salary
cout "old base salary: $ oldBaseSalary endl; print old salary
derivedPtrsetBaseSalary oldBaseSalary ; provide a raise
cout "new base salary with increase is: $ derivedPtrgetBaseSalary endl; get the new salary
end if
cout "earned $ employeePtrearnings
;
downcast pointer
@ STUDENT TO DO : Change the Hourly rate of the Hourly Employee and give increase in houlry rate
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started