C++ program to illustrate Multilevel Inheritance

Saturday, March 13th, 2010

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

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="<
Avatar Image

Author Name :
Ranjith

Total : 6 Comments


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

  1. hazarath says:

    ok …youn arec good

  2. kishan lal joshi says:

    please sir write full program on the give above of mulipal inheritance and send krishango16@gmail.com

  3. /********* 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();

    }

  4. 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();

    }

  5. dhara says:

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

  6. khushboo garg says:

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

Leave a Reply

Question and Answer
C/C++ Unix & Linux Wordpress
Source codes
C C++ Java

Free email signup