Skip to main content

Simple Program for Multiple Inheritance

2 min read Updated June 30, 2026
Share:
On this page (7sections)

Aim

To find out the student details using multiple inheritance.

Simple Program for Multiple Inheritance Algorithm/Steps:

  • Step 1: Start the program.
  • Step 2: Declare the base class student.
  • Step 3: Declare and define the function get() to get the student details.
  • Step 4: Declare the other class sports.
  • Step 5: Declare and define the function getsm() to read the sports mark.
  • Step 6: Create the class statement derived from student and sports.
  • Step 7: Declare and define the function display() to find out the total and average.
  • Step 8: Declare the derived class object,call the functions get(),getsm() and display().
  • Step 9: Stop the program.

Simple Program for Multiple Inheritance

#include<iostream.h>
#include<conio.h>

class student {
protected:
    int rno, m1, m2;
public:

    void get() {
        cout << "Enter the Roll no :";
        cin>>rno;
        cout << "Enter the two marks   :";
        cin >> m1>>m2;
    }
};

class sports {
protected:
    int sm; // sm = Sports mark
public:

    void getsm() {
        cout << "\nEnter the sports mark :";
        cin>>sm;

    }
};

class statement : public student, public sports {
    int tot, avg;
public:

    void display() {
        tot = (m1 + m2 + sm);
        avg = tot / 3;
        cout << "\n\n\tRoll No    : " << rno << "\n\tTotal      : " << tot;
        cout << "\n\tAverage    : " << avg;
    }
};

void main() {
    clrscr();
    statement obj;
    obj.get();
    obj.getsm();
    obj.display();
    getch();
}

Sample Output

Enter the Roll no: 100

Enter two marks

90
80

Enter the Sports Mark: 90

Roll No: 100
Total    : 260
Average: 86.66

How It Works

This C++ program demonstrates Simple Program for Multiple Inheritance. It first reads the required values as input, then performs the core operation step by step, and finally prints the output shown in the Sample Output above.

  1. Declare the variables that hold the program’s data.
  2. Read the input values that the program will work with.
  3. Print the final result to the console so you can compare it with the sample output.

Try changing the input values and re-running the program to see how the output changes — this is the fastest way to understand how the logic behaves.

Learn the concept first, then study the code:

Frequently Asked Questions

What does this C++ program do?
It is a C++ example program that demonstrates Simple Program for Multiple Inheritance, including the complete source code and the expected sample output.
How do I compile and run this C++ program?
Save the code in a `.cpp` file, compile it with `g++ filename.cpp -o program`, then run it with `./program` (or `program.exe` on Windows).
What concepts does this example use?
This example uses reading user input and user-defined functions, illustrating a common pattern in C++ programming.

Related Tutorials

Search tutorials