0% found this document useful (0 votes)
21 views

Function Over Loading

The document describes an experiment on function overriding, multiple inheritance and multilevel inheritance in C++. It provides examples and explanations of these concepts. It then lists two tasks - to create classes for employees, managers, scientists and laborers with inheritance and additional fields, and to create classes for teacher, writer and scholar with multiple inheritance.

Uploaded by

UMAIR Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Function Over Loading

The document describes an experiment on function overriding, multiple inheritance and multilevel inheritance in C++. It provides examples and explanations of these concepts. It then lists two tasks - to create classes for employees, managers, scientists and laborers with inheritance and additional fields, and to create classes for teacher, writer and scholar with multiple inheritance.

Uploaded by

UMAIR Khan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

AIR UNIVERSITY

DEPARTMENT OF ELECTRICAL & COMPUTER


ENGINEERING
EXPERIMENT NO 7

Lab Title: Function Overriding, Multiple & Multi level inheritance


Student Name: Reg. No:

Objective:

LAB ASSESSMENT:

Excellent Good Average Satisfactory Unsatisfactory


Attributes
(5) (4) (3) (2) (1)
Ability to Conduct
Experiment
Ability to assimilate the
results
Effective use of lab
equipment and follows
the lab safety rules

Total Marks: Obtained Marks:

LAB REPORT ASSESSMENT:


Excellent Good Average Satisfactory Unsatisfactory
Attributes
(5) (4) (3) (2) (1)

Data presentation

Experimental results

Conclusion

Total Marks: Obtained Marks:

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

Overriding member functions of the base class


• A derived class can override the member functions of its base class
• To override a function of base class, the derived class provides a function with same
signature as that of the base class. So derived class function overrides the base class
function
• Base class functions are overridden if we want to change the functionality of base class
function
• Functions can be totally changed
• A few new additions can be made in the overriding function
• Derived class method and base class method have same signatures but when this
function is called on a derived class object, the function of derived class object will be
called although the base class functions are making the interface of the derived class
• To explicitly call the base class overridden function, use
parent_class_name::member_function_name(…)

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

a) a no-argument constructor for initializing the fields to default values

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.

d) An accessor function to display the values of the fields.

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.

You might also like