//sample program for Class Hierarchies
# include < iostream.h >
class employee 
 {
private: char name[80];
unsigned long number;
public:
void getdata() 
{
cout << "\n Enter last name";
cin.getline(name,80); 
cout << "\n Enter number"; cin >> number;  
}
void dispdata()
{ 
cout << "\n Name:" << name ;
cout << "\n Number : "<< number; }  
};  // class employee ends here 
class manager: public employee
{
private: char title[80];
public : void getdata()
{ 
employee :: getdata( ); 
cout << "title: "; cin.getline(title,80);
}
void dispdata()
{
employee :: dispdata( );	
cout << "\n Title :" << title << endl;
}
};

class scientist: public employee
{
private: int papers;
public : void getdata()
{ 
employee :: getdata();
cout << "Enter papers published :"; 
cin >> papers;
}
void dispdata()
{ 
employee :: dispdata();
cout << "\n Number of publications :" << papers; 
}  
};
void main()
{
manager m1;
scientist S1;
cout << endl << "Manager"; m1.getdata(); 
cout << "\nData "; m1.dispdata();
cout << endl << "Scientist "; 
s1.getdata(); 
cout << "\nData ";s1.dispdata();
}
Click here to go back.

Our aim is to provide information to the knowledge seekers. 


comments powered by Disqus




Footer1