Simple Program for Multiple Inheritance Using C++ Programming
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
Inheritance In C++ Programs
- Simple Program for Single Inheritance Using C++ Programming
- Simple Program for Multiple Inheritance Using C++ Programming
- Simple Inheritance Base Class Private Member Example Program
- Simple Inheritance Private Base Class Example Program
- Simple Multi Level Inheritance Example Program
- Simple Hierarchical Inheritance Example Program
Read More Articles
- Simple Merge Sort Program in C++
- Scope Resolution Operator In C++
- Simple Program for Virtual Functions Using C++ Programming
- Simple Class Example Program For Find Prime Number In C++
- Simple Example Program For Parameterized Constructor In C++
- Define Constructor in Outside Class Example Program In C++
- Simple Example Program For Copy Constructor In C++
- Simple Program for Function Overloading Using C++ Programming
- Simple Program for Single Inheritance Using C++ Programming
- Simple Program for Inline Function without Class Using C++ Programming
- Simple Example Program For Constructor In C++
- Factorial Using Function Example Program In C++
- Simple Addition ( Add Two Integers ) Example Program
- Simple Example Program for Inline Function Using C++ Programming
- Simple Program for Read user Input Using cin
- Simple Example Program For Constructor Overloading In C++
- Factorial Using Loop Example Program In C++
- Simple Stack Program in C++ Programming
- Simple Program for Friend Function Using C++ Programming
- Simple Program for Static Data and Member Function Using C++ Programming
- Simple Program for Unary Operator Overloading Using C++ Programming
- Do While Loop Example Program In C++
- Simple Program for Binary Operator Overloading Using C++ Programming
- Simple Program for Multiple Inheritance Using C++ Programming
- Simple Copy Constructor Example Program For Find Factorial In C++