You must Sign In to post a response.
  • C++ program to implement multilevel inheritance.


    Preparing for C++ Programming exams? Confused about the program solution for implementing multilevel inheritance? Find advice from our experts on this page for your queries.

    Following is a question that was asked in the question paper of B.E. Mechanical Engineering (June/July 2017)conducted by Bangalore University, for subject Object Oriented Programming(2K11 Scheme)(ME-601), Semester-VI

    This question is asked for 12 marks and hence requires some explanation. Please let me know the solution.

    Q) Write a C++ program to implement a class called PERSON having data members as name, date of birth and address. Derive a class STUDENT from PERSON having data members roll number and semester. Derive another class EXAM from STUDENT which has data members mark1, mark2 and average. Compute the average and display the details. [12 Marks]
  • Answers

    2 Answers found.
  • Inheritance is the striking feature of object oriented programming. Below is a program which involves multilevel inheritance. In multi level inheritance derived class becomes base class for further inheritance. In below program PERSON is initially base class and STUDENT is the derived class. In next inheritance STUDENT which is a derived class initially, now it becomes base class and EXAM is its derived class.
    To handle the data of birth field we use structure named as struct dob.
    Please include and header files before declaration of PERSON class.
    //PROGRAM TO GET STUDENT INFO USING MULTILEVEL INHERITANCE.
    #include
    #include
    class PERSON
    {
    protected:
    char name[20],add[20];
    struct dob
    {
    int dd,mm,yyyy;
    }d;
    public:
    void input(void)
    {
    cout<<"Enter name, date of birth and address of student\n";
    cin>>name>>d.dd>>d.mm>>d.yyyy>>add;
    }
    void display(void)
    {
    cout<<"\n Student name is "< cout<<"\n Student address is "< cout<<"\n Date of birth of student is "< }
    };
    class STUDENT:public PERSON
    {
    protected:
    int rno,sem_no;
    public:
    void get(void)
    {
    cout<<"\nEnter roll number and semester number\n";
    cin>>rno>>sem_no;
    }
    void put(void)
    {
    cout<<"\n Student roll number is "< cout<<"\n Student semester is "< }
    };
    class EXAM:public STUDENT
    {
    protected:
    int mark1, mark2,total;
    float avg;
    public:
    void indata(void)
    {
    cout<<"\nEnter marks in two tests(Enter marks out of 25)\n";
    cin>>mark1>>mark2;
    }
    void disp(void)
    {
    total=mark1+mark2;
    avg=float(total)/2;
    cout<<"\n Student marks in first test are "< cout<<"\n Student marks in second test are "< cout<<"\n Student average marks in two test are "< }
    };
    void main(void)
    {
    class EXAM e;
    clrscr();
    e.input();
    e.get();
    e.indata();
    clrscr();
    cout<<"\n Student details are as follows\n";
    e.display();
    e.put();
    e.disp();
    getch();
    }

  • student-info-program-output.docx

    Delete Attachment


  • Sign In to post your comments