Example program for inheritance

Example showing inheritance: 

#include<iostream.h>                                                          
#include<conio.h>                                                             
#include<stdio.h>   

                                                          
const int len=25;    
                                                         
class employee
{  

     private:                                                                         
     char name[len];                                                             
     unsigned long enumb;    
                                                 
     public:                                                                          
     void getdata()                                                                
     { 

           cout<<"enter name: ";                                                         
          gets(name);                                                                  
          cout<<"enter employee no. :";                                                
          cin>>enumb;                                                                
    }   

                                                                         
    void putdata()                                                                
    { 

              cout<<"name:"<<name<<"\n";                                                   
              cout<<"emp. number :"<< enumb<<"\n";                                          
              cout<<"basic salary :"<<basic; 

                                            
    }       

                                                                  
    protected:                                                                       
    float basic;
    void getbasic()                                        
    {  

              cout<<"enter basic :";                                              
              cin>>basic;     
                                  
     }       
                                              
 };        


                                                      
  class manager: private  employee                                           
  {       
                                                                  
        private:                                                                
        char title[len];    

                                                 
        public:                                                                 
        void getdata()                                                     
         { 

                       employee::getdata();                                              
                       getbasic();                                                      
                       gets(title);                                                     
                       cout<<endl;                                                       
         }       

                                                            
         void putdata()                                                     
         {  

                                                                
                      employee::putdata();                                            
                      cout<<"title: "<<title<<"\n"
                      gets(title);                                                                 
                      cout<<endl;                                                                
          }


                                                                            
        void putdata()                                                               
        {      

                                                                         
                       employee::putdata();                                                       
                       cout<<"title: "<<title<<"\n" ;       

                                      
        }           
                                                             
 };           

                                                                
void main()       
                                                            
{  

   manager m1, m2;                                                             
   cout<<"manager 1";                                                            
   m1.getdata();                                                                
   cout<<"manager 2";                                                            
   m2.getdata();                                                                
   cout<<"  manager 1 details :";                                             
   m1.putdata();                                                                
   cout<<"  manager 2 details:";                                                
   m2.putdata();                                                            

}                                                                                                                                                     

Post a Comment

0 Comments