/**  show how inheritance works using direct references
     and protected class sections
**/

#include <iostream.h>

class parent
{
   protected:
     int mine;
   public:
     parent(int x = 0) 
     {
       mine = x;
       cout << endl << "create parent "<< mine << endl;
     }
     ~parent() { cout << endl << "Destroy parent " << mine << endl;}
     void show_all(void) {cout <<endl << "show " << mine << endl;}
     void add(int x) { mine = mine + x;} 
};


class child: public parent
{
  private:
    int his;
  public:
    child(int x = 0): parent(x+3) 
    {
      his = x;
      cout << endl << "create child " << his << endl;
      cout << endl << "mine = " << mine << endl;
    }
    ~child() {cout << endl << "Destroy child " << his << endl;}
    void show_all(void) 
    {cout << endl << "show kid " << his << "and ";
     cout << mine << endl;
    }
};



void main(void)
{
  parent mom, dad(10);
  child kid(3);

  mom.show_all();
  dad.show_all();
  mom.add(10);
  dad.add(10);
  mom.show_all();
  dad.show_all();
  kid.show_all();
} 

//output from above program
create parent 0
create parent 10
create parent 6
create child 3
mine = 6
show 0
show 10
show 10
show 20
show kid 3and 6
Destroy child 3
Destroy parent 6
Destroy parent 20
Destroy parent 10