Inheritance

[Set – 1]

Question 1. Consider the following declaration and answer the questions given below :

class PPP
{
    int H: 
  protected :
    int S;
  public :
    void input (int);
    void out();
};

class QQQ : private PPP
{
    int T;
  protected :
    int U;
  public :
    void indata(int, int);
    void outdata();
};

class RRR : public QQQ
{
    int M;
  public :
    void disp();
};

i. Name the base class and derived class of the class QQQ.
ii. Name the data member(s) that can be accessed from function disp().
iii. Name the member function(s), which can be accessed from the objects of class RRR.
iv. Is the member function out() accessible by the object of the class QQQ?

 

Question 2. Answer the questions (i) to (iv) based on the following:

class Publisher
{
    char pub[12];
    double turnover;
  protected:
    void register();
  public:
    Publisher();
    void enter();
    void display();
};

class Branch
{
    char city[20];
  protected:
    float employees;
  public:
    Branch();
    void haveit();
    void giveit();
};

class Author : private Branch, public Publisher
{
    int acode;
    char aname[20];
    float amount;
  public:
    Author();
    void start();
    void show();
};

i. Write the names of data members, which are accessible from objects belonging to class Author.
ii. Write the names of all the member functions which are accessible from objects belonging to class Branch.
iii. Write the names of all the members which are accessible from member functions of class Author.
iv. How many bytes will be required by an object belonging to class Author?

Question 3. Consider the following declarations and answer the question given below :

class Vehicle
{
  private:
    int wheels;
  protected :
    int passenger:
  public :
    void inputdata(int, int);
    void outputdata();
};

class Heavyvehicle : protected Vehicle
{
    int diesel_petrol;
  protected :
    int load;
  public:
    void readdata(int, int);
    void writedata();
};

class Bus : private Heavyvehicle
{
    char make[20];
  public :
    void fetchdata(char);
    void displaydata();
};
        

(i) Name the base class and derived class of the class Heavyvehicle.
(ii) Name the data member(s) that can be accessed from function displaydata().
(iii) Name the data member's that can be accessed by an object of Bus class.
(iv) Is the member function outputdata() accessible to the objects of Heavyvehicle class.

 

Question 4. Answer the questions (i) to (iv) based on the following code :

class Drug
{
    char category[10];
    char date_of_manufacture[10];
    char company[20];
  public:
    Drug();
    void enterdrugdetails();
    void showdrugdetails();
};

class Tablet : public Drug
{
  protected:
    char tablet_name[30];
    char volume_label[20];
  public:
    float price;
    Tablet();
    void entertabletdetails();
    void showtabletdetails ();
};

class PainReliever : public Tablet
{
    int dosage_units;
    char side_effects[20];
    int use_within_days;
  public:
    PainReliever();
    void enterdetails();
    void showdetails();
};

(i) How many bytes will be required by an object of class Drug and an object of class PainReliever respectively ?
(ii) Write names of all the data members which are accessible from the object of class PainReliever.
(iii) Write names of all the members accessible from member functions of class Tablet.
(iv) Write names of all the member functions which are accessible from objects of class PainReliever.