C++ program of multilevel inheritance

      No Comments on C++ program of multilevel inheritance

Program of multilevel inheritance

C++ program of multilevel inheritance.Multilevel inheritance means derive a class from base class which itself has been derived from another class.The class scan2 is known as intermediate base class since it provides the link for inheritance between class scan1 and scan3.

Program of multilevel inheritance

#include<iostream.h>
#include<conio.h>
class scan1
{
  public:
  int x;
  public:
  void get1()
  {
   cout<<"Enter number:- ";
   cin>>x;
  }
  void res1()
  {
   if(x%2==0)
   {
    cout<<"Number is even"<<endl;
   }
   else
   {
    cout<<"Number is odd"<<endl;
   }

  }
};
class scan2:public scan1
{
 public:
 int y,z;
 public:
 void get2()
 {
  cout<<"..........................."<<endl;
  cout<<"Enter second number:- ";
  cin>>y;
 }
 void res2()
 {
  z=x+y;
  cout<<"Sum of two number is:- "<<z<<endl;
   cout<<"..........................."<<endl;
 }
};
class scan3:public scan2
{
 public:
 int a,b;
 public:
 void get3()
 {
 cout<<"Enter third number:- ";
 cin>>a;
 }
 void res3()
 {
  b=a+z;
  cout<<"Sum of three number is:- "<<b<<endl;
 }
};
void main()
{
 clrscr();
 scan3 s;
 s.get1();
 s.res1();
 s.get2();
 s.res2();
 s.get3();
 s.res3();
 getch();
}

OUTPUT:-

Program of multilevel inheritance


Comment below if you are facing any problem.


Also read

C++ program swap two numbers using single inheritance
C++ program to find greatest between three numbers using single inheritance


Summary
C++ program of multilevel inheritance
Article Name
C++ program of multilevel inheritance
Description
This program illustrate the concept of multilevel inheritance.Multilevel inheritance means derive a class from base class which itself has been derived from another class.
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

Your email address will not be published. Required fields are marked *