Class Hierarchies





Class Hierarchies

The relationship between a base ad derived classes is refer to as class hierarchy. This hierarchy establishes is –a relationship. This is a relationship implies generalization /specialization between the base class and derived class.

A program given below consists  of a base class employee. This class handles the employee’s last name and employee number from this class, three other classes are derived: manager, scientist, labor. The manager and scientist classes contain additional information about this category of employee and member function to handle this information.

#include<iostream.h>

#include<conio.h>

Const int len=80;

Class employee

{

Private:

Char name [len];

Long it number;

Public:

Void getdata ()

{

Cout<<”\n Enter name”;

Cin>>name;

Cout<<”\n enter numbers”;

Cin>>numbers;

}

Void putdata ()

{

Cout<<”\n Name=”<<name;

Cout<<”\n Number=”<<number;

}

};

Class manager: public employee

{

Private:

Class title [len];

Double dues;

Public:

Void getdata ()

{

Employee:: getdata ();

Cout<<”\n enter title”;

Cin>>titile;

Cout<<”\n enter golf club dues”;

Cin>>dues;

}

Void putdata ()

{

Employee:: putdata ();

Cout<<”\n Title :”<< title;

Cout<<”\n golf club dues”<<dues;

}

};

Class scientist: public employee

{

Private:

Int pubs;

Public:

Void getdata ()

{

Employee:: getdata ();

Cout<<”\n enter number of publication”;

Cin>>pubs;

}

Void putdata ()

{

Employee:: putdata (0;

Cout<<”\n Number of publication”<<pubs;

}

};

Class laborer: public employee

{

};

Void main ()

{

Manager m1;

Scientist s1;

Laborer l1;

Cout<<”\n enter date for manager”;

m1.getdata ();

Cout<<”\n enter date for scientist”;

s1.getdata ();

Cout<”\n enter date for laborer”;

l1.getdata ();

Cout<<”\n Data on manager”;

m1.putdata ();

Cout<<”\n data on scientist”;

s1.putdata ();

Cout<<”\n data on laborer”;

l1.putdata ();

getch ();

}



Related posts:

  1. Array of class objects Array of class objects and single inheritance A program consisting...
  2. Array Of Class Object Array of class objects Array is a collection of similar...
  3. Defining Member Function In C++ Class methods definitions  (Defining the member functions) Member functions can...
  4. Inheritance in C++ Inheritance in C++ Inheritance is one of the most important...
  5. Class In C++ Class in c++ Class is a group of similar object....