Multiple inheritance program in c++

      No Comments on Multiple inheritance program in c++

Multiple inheritance program

Multiple inheritance program in c++.A class that can inherit the attribute of two or more classes is known as multiple inheritance.

Multiple inheritance program

Here class scan3 is derived class which inherit the atributes of class scan1 and scan2.

Program

#include<iostream.h>
#include<conio.h>
class scan1
{
  public:
  int x;
  public:
  void get1()
  {
   cout<<"Enter number to find factorial:- ";
   cin>>x;
  }
};
class scan2
{
 public:
 int y,z;
 public:
 void get2()
 {
  cout<<"..........................."<<endl;
  cout<<"Enter number to find reverse:- ";
  cin>>y;
 }
};
class scan3:public scan1,public scan2
{
 public:
 int b;
 int i,a;
 double c;
 public:
 void fact();
 void rev();
};
void scan3::fact()
{
  c=1;
  for(i=x;i>=1;i--)
  {

   c=c*i;
  }
 cout<<"Factorial of number is:- "<<c<<endl;
}
void scan3::rev()
{      b=0;
 while(y>0)
 {
       b=b*10;
       b=b+y%10;
       y=y/10;
 }
 cout<<"Reverse of a number is:- "<<b<<endl;
}
void main()
{
 clrscr();
 scan3 s;
 s.get1();
 s.get2();
 s.fact();
 s.rev();
 getch();
}

OUTPUT

Multiple inheritance program


Comment below if you are facing any problem.


Also read

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


Summary
Multiple inheritance program in c++
Article Name
Multiple inheritance program in c++
Description
A class that can inherit the attribute of two or more classes is known as multiple inheritance.
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

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