C++ program to illustrate Multilevel Inheritance

MULTILEVEL INHERITANCE

AIM:
A program to illustrate multilevel inheritance. we have three classes, student, test and result. Here class student is the base class. And the class test is derived from the base class student. And the another class result is derived from the class test.

ALGORITHM:

• Start the process
• Invoke the base class student
• Invoke the derived class test which in inherited by the class student
• Invoke the derived class result which in inherited by the class test
• Create an object student1 for the result class
• Call student1.getno(),assign the value of rno in student class
• Call student1.getmarks(),assign the marks in test class
• Call student1.display(),for displaying the result
• Stop the process

Start exploring endless computing possibilities with your own Raspberry Pi computer and accessories. Perfect for beginners and students.

PROGRAM

#include
#include
class student
{
   		protected:
   		int rno;
   		public:
   		void getno(int);
   		void putno(void);
};
void student::getno(int a)
{
rno=a;
}
void student ::putno()
{
cout<<"rollno="<Tags: , , , , 

15 Responses to “C++ program to illustrate Multilevel Inheritance”

  1. /********* IMPLEMENTATION OF MULTILEVEL INHERITANCE *********/

    #include
    #include

    class student // Base Class
    {
    protected:
    int rollno;
    char *name;
    public:
    void getdata(int b,char *n)
    {
    rollno = b;
    name = n;
    }
    void putdata(void)
    {
    cout< < " The Name Of Student \t: "< < name< < endl;
    cout< < " The Roll No. Is \t: "< < rollno< < endl;
    }
    };

    class test:public student // Derieved Class 1
    {
    protected:
    float m1,m2;
    public:
    void gettest(float b,float c)
    {
    m1 = b;
    m2 = c;
    }
    void puttest(void)
    {
    cout< < " Marks In CP Is \t: "< < m1< < endl;
    cout< < " Marks In Drawing Is \t: "< < m2< < endl;
    }
    };

    class result:public test // Derieved Class 2
    {
    protected:
    float total;
    public:
    void displayresult(void)
    {
    total = m1 + m2;
    putdata();
    puttest();
    cout< < " Total Of The Two \t: "< < total< < endl;
    }
    };

    void main()
    {
    clrscr();
    int x;
    float y,z;
    char n[20];
    cout< >n;
    cout< >x;
    result r1;
    r1.getdata(x,n);
    cout< >y;
    cout< >z;
    r1.gettest(y,z);
    cout< < endl< < endl< < "************ RESULT **************"< < endl;
    r1.displayresult();
    cout< < "**********************************"< < endl;
    getch();

    }

    Reply
  2. A.BHARAJA IS A INDIAN

    /********* IMPLEMENTATION OF MULTILEVEL INHERITANCE *********/

    #include
    #include

    class student // Base Class
    {
    protected:
    int rollno;
    char *name;
    public:
    void getdata(int b,char *n)
    {
    rollno = b;
    name = n;
    }
    void putdata(void)
    {
    cout< < " The Name Of Student \t: "< < name< < endl;
    cout< < " The Roll No. Is \t: "< < rollno< < endl;
    }
    };

    class test:public student // Derieved Class 1
    {
    protected:
    float m1,m2;
    public:
    void gettest(float b,float c)
    {
    m1 = b;
    m2 = c;
    }
    void puttest(void)
    {
    cout< < " Marks In CP Is \t: "< < m1< < endl;
    cout< < " Marks In Drawing Is \t: "< < m2< < endl;
    }
    };

    class result:public test // Derieved Class 2
    {
    protected:
    float total;
    public:
    void displayresult(void)
    {
    total = m1 + m2;
    putdata();
    puttest();
    cout< < " Total Of The Two \t: "< < total< < endl;
    }
    };

    void main()
    {
    clrscr();
    int x;
    float y,z;
    char n[20];
    cout< >n;
    cout< >x;
    result r1;
    r1.getdata(x,n);
    cout< >y;
    cout< >z;
    r1.gettest(y,z);
    cout< < endl< < endl< < "************ RESULT **************"< < endl;
    r1.displayresult();
    cout< < "**********************************"< < endl;
    getch();

    }

    Reply
  3. atala badha hard program n hoy…..example tarikhe easy program apvana hoy…..

    Reply
  4. khushboo garg

    content should be in elaborate condition,it s not sufficient to understand.

    Reply
  5. manimozhi

    cotent might be small for easy understanding.much more programs must be displayed
    for further reference

    Reply
  6. Krishna

    Write a program to declare class ‘student’ having data members roll no and names.declare one more class ‘teacher’ having data members name and subject.inherite a new class ‘info’ from these two base classes .accept and display data of ‘student’ and ‘ teacher’ for one object of class ‘info’

    Reply
  7. if derived class 2 is inherited privately!!!
    then
    can we make an object of that class (derived class 2) in the MAIN() ?????

    Reply
  8. Jeslin sheeba

    Why you have not wrote the header file like this?
    #include
    #include

    Reply

Leave a Reply