This is a sample C++ program on Multiple Inheritance. Using Multiple Inheritance, this program will display marks of a students.
#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 Marks Gained In Two Subjects:";
cin>>m1>>m2;
}
};
class sports
{
protected:
int sm;
public:
void getsm()
{
cout<<"\nEnter The Marks Gained In Sports:";
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();
}
OUTPUT:
Enter The Roll No:
51
Enter The Marks Gained In Two Subjects:
95
90
Enter The Marks Gained In Sports:
85
Roll No: 51
Total: 270
Average: 90
Comments
Post a Comment
Please share your opinions and suggestions or your experience in the comments section. This way we can all help each other...
Experienced guys can share their resumes at admin@interview-made-easy.com