PVG's College of Engineering and Technology & G. K.
Pate (Wani) Institute of
Management, Pune-411009
Accredited by NAAC with Grade “A”
Department of Electronics and Telecommunication
Engineering
Experiment 10: Write a program in C++ to Read and Display the information of Employee Using
Multiple Inheritance. Use Basic Info and Department Info as a base classes of
Employee class
.
Name: Class: S.E. Division: I / II
Roll No: Date of Submission:
Marks Obtained: /20 Signature of the subject teacher:
Aim: Write a program in C++ to Read and Display the information of Employee Using
Multiple Inheritance. Use Basic Info and Department Info as a base classes of
Employee class
Objective: To learn the concepts of Inheritance and its types
.
Mapped Outcome: After completing the experiment, the students will be able to:
Apply the concepts of classes, methods inheritance and polymorphism to write programs
C++.
Software tools required: Quincy, Eclipse, Turbo C++
Theory: hierarchical classifications. Using inheritance, we can create a general class that
defines traits common to a set of related items. This class may then be inherited by other,
more specific classes, each adding only those things that are unique to the inheriting class.
When a class inherits another, the members of the base class become members of the derived
class. Class inheritance uses this general form:
How to inherit class in C++ programming?
Class derived_class_name : <Access_specifier> base_class_name
{
// derived class members.
// body of class
};
The access status of the base-class members inside the derived class is determined by access.
The base-class access specifier must be public, private, or protected. If no access specifier is
present, the access specifier is private by default if the derived class is a class. The base class
is also called as parent class and the derived class is also called as the child class.
This concept of Inheritance leads to the concept of polymorphism.
Features or Advantages of Inheritance:
Reusability:
Inheritance helps the code to be reused in many situations. The base class is defined and once
it is compiled, it need not be reworked. Using the concept of inheritance, the programmer
can create as many derived classes from the base class as needed while adding specific
features to each derived class as needed.
Saves Time and Effort:
The above concept of reusability achieved by inheritance saves the programmer time and
effort. Since the main code written can be reused in various situations as needed.
Increases Program Structure which results in greater reliability
‘Types of Inheritance’
Basically inheritance is categorized based on the number of classes involved and the relationship
existing between them. The types of inheritance are as follows,
1. Single Inheritance
2. Multi-level Inheritance
3. Multiple Inheritance
4. Hierarchical Inheritance
5. Hybrid Inheritance
1. Single Inheritance: This involves two classes, in which one class inherits the
capabilities of another class. The class whose capabilities are inherited is called base
class and the class that inherits the properties is called derived class.
2. Multi-level Inheritance: This type of inheritance involves more than two classes in a
levelled structure, where each class inherits only a single class just above it. The
classA at the top is the base class, the class just below A is the child class of A and parent
class of C.
3. Multiple Inheritance: Multiple inheritance involves a single class inheriting
properties of more than one class simultaneously. In this there is one child class with
multiple parent class, hence the name ‘Multiple Inheritance’. In this class A and Class
B are parent classes of class C.
4. Hierarchical Inheritance: This type of inheritance has a rooted tree structure. There
is a single generalized parent class, which has two or more derived specialized
classes, called the child class. Each child inherits the basic functionality of the base
class and adds some extra features to it.
5. Hybrid Inheritance: This type of inheritance involves more than one of the above
types of inheritance.
‘Access Specifier’
There are following three access specifier available in C++, which are as follows
1. Public: The public derivation means that the derived class can access the public and
protected members of the base class but not the private members of the base class.
With public access specifier the public members of the base class become public
members of the derived class and the protected members of the base class become the
protected members of the base class.
2. Private: The private derivation means that the derived class can access the public and
private members of the base class privately. With privately derived class, the public
and protected members of the base class become private members of the derived
class.
3. Protected: The protected derivation means that the derived class can access the
public and private members of the base class protectedly. With protectedly derived
class, the public and protected members of the base class become protected members
of the derived class.
Syntax the class derived_class_name derives from the base_class_name using Colon operator
but the visibility of the base_class functionalities in the derived_class depends on the
Access_specifier it may be either private or public.
The following table illustrates how visibility of base class members will undergo
modifications in all the three kinds of derivation
Table 1. Visibility of Inherited Base class Member in Derived class.
This can also depict in diagrammatical form:
What is inherited?
When inheritance is done, various links and tables (index, virtual etc) are created
which are used to provide the accessibility of the members of the base class in
derived class and in other class hierarchy. This means saying “public members are
inherited” is better to say as “public members become accessible”.
A derived class inherits every member of a base class except:
1. its Constructors, destructors and copy constructors of the base class
2. its friends
3. its operator =,( ) members
Procedure:
1. Draw UML Diagram
2. Compile the written code.
Results: Attach the print of code and output of program.
Conclusion:……………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
……………
Remarks by Subject teacher about correctness and improvements:
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
Acknowledgement: My sincere thanks to
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
…………………………………………………………………………………………………
Reference:
1. E Balagurusamy, “Object Oriented Programming Using C++”, Tata McGraw-Hill
2. Herbert Schildt , “ The Complete Reference TO C++” Tata McGraw-Hill,3RD Edition.
3. Bjarne Stroustrup, “C++ Programming Language”, Pearson Education
4. .Robert Lafore, “Object-Oriented Programming in C++ “,Pearson Education India , (4th
Edition)
5. Yeshwant Kanetkar “Let us C++”, BPB Publications
6. www.programiz.com
Assignment:
1. Explain Diamond problem in Inheritance with example.
2. Identify the inheritance type and write its C++ code.
class employee
(a)
Important Notes:
Note1. Following points should be considered while writing the conclusion: benefit of using
Inheritance concept
Note2.Print all the documents back to back on every page. Save pages to save trees.
Note3.Printing on single side will reduce the marks
Note4.Plagiarism of any form is strictly prohibited and attract towards reduction in marks
Note4.Submit the assignments well in time i.e. within four days of performing the
experiment to get maximum marks.
Sign Submission Attendance(10) Submission(5) Understanding Total
Date (5) (20)
UML Diagram: