C++ Programming

Program to Implement Multiple Inheritance C++

Write a Program to Implement Multiple Inheritance.

  1. Single Inheritance
  2. Hierarchical Inheritance
  3. Multilevel Inheritance

Source Code

#include<iostream>

#include<conio.h>

using namespace std;

class mom

    {

            protected:

            char name[20];

            int age;

            public:

            void getdata()

        {

            cout<<"Enter Mom Name: ";

            cin>>name;

            cout<<"Enter Mom Age: ";

            cin>>age;

        }

void showdata()

        {

            cout<<"Mom Name: "<<name<<endl;

            cout<<"Mom Age: "<<age<<endl;

        }

    };

class dad

    {

        protected:

        char name[20];

        int age;

        public:

        void getdata()

    {

        cout<<"Enter Dad Name: ";

        cin>>name;

        cout<<"Enter Dad Age: ";

        cin>>age;

    }

void showdata()

        {

            cout<<"Dad Name: "<<name<<endl;

            cout<<"Dad Age: "<<age<<endl;

        }

    };

class family:public mom,public dad

    {

public:

void getdata()

        {

            mom::getdata();

            dad::getdata();

            cout<<endl<<"DISPLAY FAMILY"<<endl;

            mom::showdata();

            dad::showdata();

        }

    };

int main()

    {

        family a;

        a.getdata();

        getch();

    }

Output

Multiple Inheritance

Back to top button