Hierarchical inheritance program in c++

      No Comments on Hierarchical inheritance program in c++

Hierarchical inheritance program

Hierarchical inheritance program in c++.It is a kind of inheritance in which one class is inherited by many sub classes.

Hierarchical inheritance program

Program

#include<iostream.h>
#include<conio.h>
class scan1
{
  public:
  float x,y;
  public:
  void get()
  {
   cout<<"Enter first number:- ";
   cin>>x;
   cout<<"Enter second number:- ";
   cin>>y;
  }
};
class scan2:public scan1
{
 public:
  int a;
 public:
 void res2()
 {
  a=x+y;

  cout<<"Sum of two number is:- "<<a<<endl;
  cout<<"..........................."<<endl;
 }
};
class scan3:public scan1
{
 public:
 int b;
 public:
 void res3()
 {
 b=x*y;
 cout<<"Multiplication of two numbers is:- "<<b<<endl;
   cout<<"..........................."<<endl;
 }
};
class scan4:public scan1
{
 public:
 float c;
 public:
 void res4()
 {
  c=x/y;
  cout<<"Division of two numbers is:- "<<c<<endl;

 }

};
void main()
{
 clrscr();
 scan2 s2;
 scan3 s3;
 scan4 s4;
 cout<<".....Numbers for addition..... "<<endl;
 s2.get();
 s2.res2();
 cout<<".....Number for multiplication..... "<<endl;
 s3.get();
 s3.res3();
 cout<<".....Number for division..... "<<endl;
 s4.get();
 s4.res4();
 getch();
}

OUTPUT

hierarchical inheritance program


Comment below if you are facing any problem


Also read

C++ program of multilevel inheritance
Multiple inheritance program in c++
C++ program to find greatest between three numbers using single inheritance


Summary
Hierarchical inheritance program in c++
Article Name
Hierarchical inheritance program in c++
Description
It is a kind of inheritance in which one class is inherited by many sub classes.
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

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