Homework 5 - Inheritance and Polymorphism
Due: Wednesday, March 4, 2009 at 5:00pm
Coding Conventions
Use the same coding conventions as described in
Homework 1. Additionally, make sure to indent each
section of the class in the class definition.
Assignment
The purpose of this assignment is to create two children classes that use
polymorphism for some of their functions.
You will define the following class hierarchy:
Employee
/ \
/ \
/ \
hourlyEmployee salariedEmployee
The Employee class will be similar to, but NOT identical to, the class
used in Lab 6. Use
hw5main.cpp as your main function. Note that it
uses a parent class pointer to call the polymorphic function. If you use
seperate compilation, you will need to modify hw5main.cpp to include the
filenames you use for your header files. Also, be sure to submit all files
(header files, implementation files and the modified hw5main.cpp) if you
use seperate compilation. Alternatively, you can just code all of these
class within hw5main.cpp and submit just that file.
Use the following lists of features to code each class.
Employee class
The is the parent class. It will define the name and social security number.
Unlike Lab 6, it will have no useful public functions for the outside world
to use. Most of the functions will be in the protected section for the two
children class to access. The only public functions will be the ones used
for polymorphism.
- Private section
-
- A character array or string for the name
- A character array or string for the SSN
- An integer for the number of weeks included in the pay period
- Protected section
-
- void setName(char *) - Takes a character array or string (change the
parameter list if you use a string). Copies that into the name variable.
- const char* getName() - Returns a character array or string (change the
return type if using a string) containing the current name.
- bool setSSN(char *) - Takes a character array or string (change the
parameter list if you use a string). Verifies that there are 9
digits (see Lab 6 for how to do this). If there are 9 digits, copies to
the SSN and returns true. Otherwise, rejects the string by returning false
and leaves SSN as it is.
- const char *getSSN() - Returns a character array or string (change the
return type if using a string) containing the current SSN.
- bool setWeeks(int) - Verifies that the given int is one or higher. If it
is, it copies the integer over to the number of weeks in the current pay
period and returns true. Otherwise, it leaves the weeks untouched and
returns false.
- int getWeeks() - Returns the number of weeks in the pay period.
- Public section
-
- Default constructor - Set the name and SSN to the empty string. Sets weeks
to 0.
- Copy constructor - Copy the name, SSN and weeks from the source object.
- virtual void printEmployee() - For this class, print "Undefined employee"
to standard out (the screen).
hourlyEmployee class
This class inherits from the Employee class publically. It defines an employee
who gets paid by the hour. Be sure to verify that the hours worked are positive
and that the rate is above minimum wage.
- Private section
-
- A double for the hourly rate the employee is paid
- A double for the hours the employee has worked this pay period
- Public section
-
salariedEmployee class
This class inherits from the Employee class publically. It defines an employee
who gets paid a fixed, monthly salary. Be sure to verify that the monthly
salary is positive.
- Private section
-
- A double for the monthly salary
- Public section
-