Homework 4 - Basic Inheritance
Due: Wednesday, February 17, 2009 at 5:00pm
NOTE: No late assignments will be accepted beyond Friday February 19th
so that the solutions can be posted before Midterm 2.
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.
You will define the following class hierarchy:
Employee
/ \
/ \
/ \
hourlyEmployee salariedEmployee
Use hw4main.cpp as your main function. If you use
seperate compilation, you will need to modify hw4main.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 hw4main.cpp) if you
use seperate compilation. Alternatively, you can just code all of these
class within hw4main.cpp and submit just that file.
Use the following lists of features to code each class.
Employee class
The is the parent class. It defines the name and social security number.
It also defines how many weeks are in the pay period for the employee.
- 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
- 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.
- 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.
- void setEmployee() - Prompts the user for the name, SSN and weeks worked.
Uses the set functions (setName,
setSSN, etc) to set the values. If any of the set functions returns
false (invalid data has been given), the user will be prompted to re-enter
that piece of information.
- 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
-