latest Post

C + + part-15( inheritance - multilevel inheritance & hybrid inheritance )










So hey guys we are here to teach you today multilevel inheritance this is a simple thing in which we have to create the a class and then a sub-class from the class and another sub-class from the previous sub-class and this is a process to create classes from class and there are some more but this is called
multilevel inheritance .
In hybrid inheritance we have to combine two or more type of inheritance and you can suggest by it's name hybrid combination of two or more .
And the code will be easier to understand the code if you will seethe previous article of this series you don not go to anywhere i have given the link below o check it if don't see anyone

ALL THE ARTICLE OF C + +


Let's get straight to the CODE..................................................................................................................

MULTILEVEL INHERITANCE

WE HAVE TO CREATE A CLASS AND THEN A SUB CLASS FROM THE PRIMARY CLASS AND AGAIN A SUB CLASS FROM THE SUBCLASS .

..........................................................................CODE.............................................................................

            THE DIAGRAM OF THE MULTIPLE IHERITANCE FOR YOUR UNDERSTANDING

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

class student 
{
       protected :
       int roll_no;
       char name [30] ;
}
class exam : public student
{
       protected : 
       int sub1,sub2 ;
}
class result : public exam
{
       int total_marks ;
       int percentage ;
       public :
                    void input ( )
                    {
                            cout<<"\n Enter roll no , name ,subject 1 marks , subject 2 marks :"
                            cin>>roll_no>>name>>sub1>>sub2 ;
                    }
                    void display ( )
                    {
                            cout<<"Roll no =\n"<<roll_no<<"Name=\n"<<name<<"Subject 1 marks=\n"                                        <<sub1<<"Subject 2 marks =\n"<<sub2<<endl ;
                            percentage = ((sub1+sub2)/200)*100;
                            cout<<"Percentage ="<<percentage<<endl;
                    }
};
void main ( )
{
        result r ;
        r.input ( ) ;
        r.display ( () ;
        getch ( ) ;
}

HYBRID INHERITANCE

In this type of inheritance we have two do a combination of two or more type of inheritance .

thanks for you time given to this article and let's meet in the another .
bye bye..............................................................................................







About hack guru

hack guru
Recommended Posts × +

0 comments:

Post a Comment