Function Over Loading
Function Over Loading
Objective:
LAB ASSESSMENT:
Data presentation
Experimental results
Conclusion
Date: Signature:
EXPERIMENT NO 7
Function Overriding, Multiple & Multi level inheritance
Objectives
In this lab students will learn,
➢ Function overriding, multiple inheritance and multilevel inheritance
Equipment required
➢ Visual Studio/ Dev C++/Eclipse installed in Windows/PC
Example
Multiple inheritance
• A class derived from two or more classes (A child class having more than 1 parents)
• The order in which the constructors of parent classes are called is not dependent on
the order of mentioning constructors in parent class initializer. It is dependent on the
order in which inheritance is specified in the derived-class definition
• For example: Petrol is derived from both liquid and fuel. A child has character of both
his/her father and mother, etc.
Example
Output
While defining class C, notice that class B is written as a first parent and class A as a second.
This is the reason the constructor of class B is called first.
Multilevel Inheritance
When one or more classes are derived from a single class than its is referred as multilevel
inheritance. The programs done in lab 6 had multilevel inheritance because all child classes
had a single parent.
LAB TASKS
Q1. Create a class Employee that has a field for storing the complete name of employee (first
and last name), a field for storing the Identification number of employees, and another field for
storing his salary. Provide
b) a 3-argument constructor for initializing the fields to values sent from outside.
c) a setter function (mutator) that sets the values of these fields by getting input from user.
Derive three classes from this employee class: Manager, Scientist, and Laborer. Manager
class has an additional data member of # of subordinates. Scientist class contains additional
information about # of publications. Laborer class is just similar to the employee class. It has
no additional capabilities. Derive a class foreman from the Laborer class that has an additional
data member for storing the percentage of quotas met by a foreman. Provide appropriate no-
argument and n-argument constructors for all the classes. Provide the overridden getter and
setter functions here too to input and output all the fields. Determine whether public, private,
or protected inheritance should be used.
Q2. Write a class Teacher that contains the attribute teacher name, age, and address. It also
contains member function to input and display its attributes. Write another class Writer that
contains the attributes writer name, address and number of books written by him. It also
contains member functions to input and display its attributes. Write another class Scholar that
inherits both Teacher and Writer classes. Write the main function to test the program using
the object of child class.