Sunday, 7 June 2015

CBSE Class 12 - Computer Science - Board Questions on Inheritance

C++ Inheritance Questions 
Asked in Board Examination

Q&A
CBSE Class 12 - Computer Science - Board Questions on Inheritance

Q1(CBSE 2004): What is inheritance? Give an example in C++ to show its implementation in C++.

Answer: Inheritance is the process of forming a new class from an existing or base class. The base class is also known as parent class or super class. It allows the new class (called derived class) to inherit properties of its parent class.Inheriatnce helps in reusability of code.
For example, a class Truck inherits from class Automobiles which itself inherits from another class vehicles.

Q2(CBSE 2004): Given the following class definitions, answer the following questions.

   class Book 
   {
      char title[20];
      char author[20];
      int no_of_pages;
      public:
        void read( );
     void show( );
   };
   
   class TextBook : private Book
   {
      int no_of_chapters, no_of_assignments;
      protected:
         int standard;
      public:
         void readtextbook( );
      void showtextbook( );
   };
   
   class PhysicsBook : public TextBook
   {
       char topic[20];
    public:
       void readphysicsbook( );
       void showphysicsbook( );
   };
  

(i) Name the members, which can be accessed from the member functions of class PhysicsBook.
(ii) Name the members, which can be accessed by an object of class TextBook.
(iii) Name the members which can be accessed by an object of class Physicsbook.
(iv) What will be the size of an object (in bytes) of class Physicsbook?

Answer: (i) no_of_chapters, no_of_assignments, standard, topic, readtextbook(), showtextbook(), readphysicsbook() and showphysicsbook().

(ii) read(), show(), readtextbook(), showtextbook()

(iii) readtextbook(), showtextbook(), readphysicsbook() and showphysicsbook()

(iv)20 + 20 + 2 + 2 + 2 + 2 + 20 = 68 bytes.

Q3 (CBSE 2013): Consider the following c++ code and answer the questions (i) to (iv):


    class Peronal 
    {
        int class, rno;
     char section;
   protected: 
      char name[20];
   public:
      Personal();
      void pEntry();
      void pDisplay();
    };
    
    class Marks : private Personal
    {
         float m[5];
   protected:
      char grade[5];
   public:
      Marks();
      void mEntry();
      void mDisplay();
    };
    
    class Result : public Marks
    {
         float total, agg;
   public:
      char finalGrade, comments[20];
      Result();
      void rCalculate();
      void rDisplay();
    };
  

(i) Which type of inheritance is shown in the above example?

(ii) Write the name of those data members which can be directly accessed from the objects of class Result.

(iii) Write the names of those member functions, which can be directly accessed from the objects of class Result.

(iv) Write the names of those data members, which can be directly accessed from mEntry( ) function of class Marks.

Answer: (i) Multilevel Inheritance

(ii) finalGrade, comments

(iii) rCalculate(), rDisplay(), mentry(), mDisplay()

(iv) m, grade, name

Q(CBSE 2013): Answer the questions (i) to (iv) based on the following:

    class Magazine
    {
        char MCode[10];
   protected: 
     char MName[20];
   public:
     Book();
     void MEnter();
     void MDisplay();
    };
    
    class Member
    {
      char MCode[10];
   protected: 
     char MName[25];
   public:
     Member();
     void MEnter();
     void MDisplay();
    };
    
    class Library : private Magazine, public Member
    {
        char LName[15];
     float Charge;
   public:
     Library();
     void LEnter();
     void LDisplay();
    };
  

(i) Which type of inheritance is shown in the above example?

(ii) Write the names of all the members, which are accessible from LEnter( ) functions of class Library?

(iii) Write name of all the members accessible through an object of class Library

(iv) What shall be the order of execution for the constructors Magazine(), Members() and Library(), when object of class Library is declared?

Answer:
(i) Multiple Inheritance

(ii) LDisplay(), Member::MEnter(), Member::MDisplay(), Magazine::MEnter(), Magazine::MDisplay(), LName, Charge, Member::MName, Magazine::MName

(iii)No Data member, Functions: LEnter(), LDisplay, Member::MEnter() and Member::MDisplay()

(iv) Order of constructors execution is: Magazine(), Mameber(), Library()

3 comments:

  1. I just hate mathematics, but after reading your whole blog post. I find that Mathematics is really very interesting subject. Now, I will join any tuition center in Melbourne to understand all about mathematics.

    ReplyDelete
  2. Just add up bytes of data members

    ReplyDelete

We love to hear your thoughts about this post!

Note: only a member of this blog may post a comment.