Programming

Program to Implement Single Inheritance in C++

Write a Program to Implement Single Inheritance in C++.

  1. Multiple Inheritance
  2. Hierarchical Inheritance
  3. Multilevel Inheritance

Single Inheritance

The inheritance in which a single derived class is inherited from a single base class is known as the Single Inheritance.

Source Code

#include<iostream>

using namespace std;

class person

{

    protected:

    char name[10];

    int age;

    char address[10];

};

class student:public person

{

    private:

    int rollno;

    public:

    void getdata()

    {

        cout<<"Enter Name: ";

        cin>>name;

        cout<<"Enter Age: ";

        cin>>age;

        cout<<"Enter Address: ";

        cin>>address;

        cout<<"Enter Roll Number: ";

        cin>>rollno;

    }

void showdata()

    {

    cout<<endl<<"DISPLAY";

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

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

    cout<<"Address: "<<address<<endl;

    cout<<"Roll Number: "<<rollno<<endl;

    }

};

int main()

    {

        student s;

        s.getdata();

        s.showdata();

       

    }

Outputs

single inheritance

Tuts

About Author

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.