Aim :A hospital wants to create a database regarding its indoor patients. The information to
store includes:
Name of the patient
Date of admission
Disease
Date of discharge
Create a class to store the date (year, month and date as its members). Create a
base class to store the above information. The member function should include functions
to enter information and display a list of all the patients in the database. Create a derived
class to store the age of the patients. List the information about all the patients to store the
age of the patients. List the information about all the pediatric patients (less than twelve
years in age).
Theory
Inheritance
The capability of a class to derive properties and characteristics from another class is called Inheritance. Inheritance is one of the most important features of Object Oriented Programming in C++. In this article, we will learn about inheritance in C++, its modes and types along with the information about how it affects different properties of the class.
types of Inheritance
1.Single inheritance
2. Multilevel inheritance
3.Multiple inheritance
4.Hierarchical inheritance
5.Hybrid inheritance
1.Single inheritance
In single inheritance, a class is allowed to inherit from only one class. i.e. one base class is inherited by one derived class only.
Syntax:
class subclass_name : access_mode base_class
{
// body of subclass
};
2. Multiple inheritance
Multiple Inheritance is a feature of C++ where a class can inherit from more than one class. i.e one subclass is inherited from more than one base class.
Syntax :
class subclass_name : access_mode base_class1, access_mode base_class2, ....
{
// body of subclass
};
3.Multiple inheritance
In this type of inheritance, a derived class is created from another derived class and that derived class can be derived from a base class or any other derived class. There can be any number of levels.
Syntax:
class C
{
... .. ...
};
class B : public C
{
... .. ...
};
class A: public B
{
... ... ...
};
4.Hierarchical inheritance
In this type of inheritance, more than one subclass is inherited from a single base class. i.e. more than one derived class is created from a single base class.
Syntax:
class derived_class1: access_specifier base_class
{
... .. ...
}
class derived_class2: access_specifier base_class
{
... .. ...
}
5.Hybrid inheritance
Hybrid Inheritance is implemented by combining more than one type of inheritance. For example: Combining Hierarchical inheritance and Multiple Inheritance will create hybrid inheritance in C++
There is no particular syntax of hybrid inheritance. We can just combine two of the above inheritance types.
Program :
Conclusion : Hence we have performed our
practical successfully