Lab 06 Inheritance
Lab 06 Inheritance
Inheritance
1. Objectives:
To familiarize the students with various concepts and terminologies of inheritance in object
oriented Programming.
2. Outcome:
2.1 After this lab the students should be able to declare the derived classes along with the
access of base class members.
2.2 They should learn the purpose of protected members and class access as well as
working with derived class constructors.
3. Introduction:
3.1. Inheritance:
Inheritance is a way of creating a new class by starting with an existing class and adding
new members. It allows a new class to be based on an existing class. The new class can
replace or extend the functionality of the existing class. The existing class is called the
base class and the new class is called the derived class. The new class inherits all the
member variables and functions (except the constructors and destructor) of the class it is
based on.
3.2. Inheritance and the “Is a” Relationship:
When an “is a” relationship exists between classes, it means that the specialized class has
all of the characteristics of the general class, plus additional characteristics that make it
special. In object-oriented programming, inheritance is used to create an “is a”
relationship between classes.
6. Post-Lab Task:
Design a class named Employee. The class should keep the following information in
•Employee name
•Employee number
•Hire date
Write one or more constructors and the appropriate accessor and mutator functions
for the class. Next, write a class named ProductionWorker that is derived from the
Employee class.
The ProductionWorker class should have member variables to hold the following
information:
•Shift (an integer)
•Hourly pay rate (a double )
The workday is divided into two shifts: day and night. The shift variable will hold an
integer value representing the shift that the employee works. The day shift is shift 1, and
the night shift is shift 2. Write one or more constructors and the appropriate accessor
and mutator functions for the class. Demonstrate the classes by writing a program that
uses a ProductionWorker object.
Hint: use to_string function for converting numeric date to string.