Header Ads Widget

Ticker

6/recent/ticker-posts

Find Product and Sum Using Hierarchical Inheritance in C++ - Digitalise Data

 

"Digitalise Data" ,"Hierarchical Inheritance in C++"


This Program Is An Example Of Hierachical Inheritance In C++

This Is The Diagram Of Hierachical
 Inheritance Programing In C++

Simply Copy And Paste This Code
______________________________________________________

// hierarchial inheritance.cpp
#include <iostream.h> 
#include <conio.h> 

class A //single base class
{
    public:
  int x, y;
  void getdata()
  {
        cout << "\nEnter value of x and y:\n"; cin >> x >> y;
  }
};
class B : public A //B is derived from class base
{
    public:
  void product()
  {
      cout << "\nProduct= " << x * y;
  }
};
class C : public A //C is also derived from class base
{
    public:
  void sum()
  {
        cout << "\nSum= " << x + y;
  }
};
void main()
{
    B obj1;          //object of derived class B
    C obj2;          //object of derived class C
    obj1.getdata();
    obj1.product();
    obj2.getdata();
    obj2.sum();
    getch();
}  //end of program


______________________________________________________

Run This Program Using Turbo C++ in Pc Or TurboCdroid in Android It Will Work

#DigitaliseData
#C++Programing

Post a Comment

0 Comments