Multiple Inheritance


The process of deriving a class from more then one base class is known as multiple inheritance. Thus in multiple inheritance there is one derived class but more then one base classes.

Multiple Inheritance

     

#include<iostream.h>
class student
{
int rollno;
char stname[20];
public:
void inputst()
{
cout<<"Enter Roll Number:";
cin>>rollno;
cout<<"Enter Name:";
cin>>stname;
}
void outputst()
{
cout<<"Roll Number:"<<rollno<<endl;
cout<<"Name:"<<stname<<endl;
}
};
class exam
{
protected:
int mark1,mark2,mark3;
public:
void inputex()
{
cout<<"Enter Marks of three Subject:";
cin>>mark1>>mark2>>mark3;
}
void outputex()
{
cout<<"Mark1:"<<mark1<<endl;
cout<<"Mark2:"<<mark2<<endl;
cout<<"Mark3:"<<mark3<<endl;
}
};
class Result:public student,public exam
{
int total;
float per;
public:
void Display()
{
total=mark1+mark2 +mark3;
per=total/3;
outputst();
outputex();
cout<<"Total="<<total;
cout<<"Percentage="<<per;
}
};
int main()
{
Result R1;
R1.inputst();
R1.inputex();
R1.Display();
return 0;
}

Download Projects


Download Programs