inputEmployee() and
printPaycheck() to be polymorphic functions in all three classes.
Also add a new polymorphic function to all three classes (Employee and the
two children classes). Call this function employeeType(). In
Employee, make this function a pure virtual function. In hourlyEmployee, have
this function print out "Hourly". In salariedEmployee, have this function
print out "Salaried". Call this function within printPaycheck()
to print out the employee type.
setSSN, setSalary and so on), you will use
exception handling. Create the following exception classes: badSSN, badWeek,
badRate, badHour and badSalary. Within each mutator function, if the input
is bad, you will throw the corresponding exception class instead of returning
false. For example, if the SSN is not exactly 9 digits, you will throw the
badSSN exception class.
In each inputEmployee() function, you will have a
try-catch block for each of the mutator functions. You will
keep asking the user for input while there is an exception thrown. The
pseudocode for doing this for the SSN is as follows:
do
ask the user for the SSN
read the SSN into a temporary character array
set flag to true
try
call setSSN
catch badSSN
output that the SSN is bad and must be exactly 9 digits
set flag to false
while flag is false
Similar logic will be used for the other mutator functions.
NOTE: You do not need to do exception handling for setName() as
it just truncates names that are too long.
main() from Lab 7 with a main()
that implements the following pseudocode to test the polymorphic functions:
create an Employee pointer
while true
ask the user if they wish to enter a hourly or salaried employee, tell them to enter "exit" to end the loop
read their response into a character array
if the user typed "hourly"
try
use new to allocate a new hourlyEmployee to the Employee pointer
catch bad_alloc
output that the allocation failed
exit program
else if the user typed "salaried"
try
use new to allocate a new salariedEmployee to the Employee pointer
catch bad_alloc
output that the allocation failed
exit program
else if the user typed "exit"
exit the loop with the break statement
else
output that the user selected an invalid employee type
continue to the next iteration of the loop
call inputEmployee() on the Employee pointer
call printPaycheck() on the Employee pointer
delete the object pointed to by the Employee pointer
end-while
This is a variation on a menu loop where the user types commands instead of
menu options. You should use strcmp() from the cstring
library to compare what they typed to the available commands.
Email me your updated employee.h, employee.cpp and main.cpp files.