In this article we are going to study about the multiple inheritance and this type of inheritance in which one sub class is made from the other classes it is mandatory to take more then one class to make the one sub class if you are doing this inheritance which called the multiple inheritance .
You can have more understanding towards this article then you should take a look on our previous article in the same series which is called C + + .
I HAVE GIVEN THE LINK BELOW : -
ALL ARTICLES OF C + + ARE HERE
SO LET'S GET STRAIGHT TO THE ARTICLE....................................................................................
MULTIPLE INHERITANCEjuu
#include<stdio.h>
#include<conio.h>
class student ( )
{
protected:
int roll no ;
char name [30];//char is a datatype in which we enter characters like alphabets and the 30 is the limit of the character
};
class exam ( ):
{
int sub1 , sub2 ;//sub1 :- subject 1 and for sub2 also
};
class result ( ) public student , exam //here public student is used after class bcz this class can access student class from any where in this code
{int total_marks ;
int percentage ;
public :
void input ( )
{
cout<<"\n Enter you roll number , name and marks of subject 1 and subject 2";
cin>>rollno>>name>>sub1>sub2;
}
void display ( )
{
total_marks = sub1+sub2;
percentage = ((sub1+sub2)/200)*100 ;
cout<<"\nTotal Marks = \nPercentage = " <<total_marks<<percentage<<endl;
}
};
void main ( )
{
result r ;
r . input ( ) ;
r.display ( ) ;
getch ( ) ;
}
...................................................END................................................
thanks for your time
have a great day .
for such more you follow if wanted
0 comments:
Post a Comment