latest Post

C + + part-12( Inheritance-single inheritance )

Hey guys  this is your's writer i am joking .so in this we are going to study today a type of the inheritance i came so late who which are following me have noticed so i will be try to be regular so let's get straight to the article .
In this we are going to study the single inheritance that it means that only one sub-class is made from only from one class.

YOU CAN SEE OUR MORE ARTICLES ON C + + BY THE LINK BELOW

LINK FOR ALL ARTICLES

So let's get start........................................................................................................................................







SINGLE INHERITANCE

THIS IS A TYPE OF INHERITANCE IN WHICH ONLY ONE CLASS CAN ACCESS THE PROPERTY OF THE OTHER CLASS .                                                                                     
LET'S GET STRAIGHT TO THE CODE...................................................................................

WE WILL MAKE TO CLASSES OF THE EMPLOYER AND THE CLASS OF THE MANAGER.                                                                                                                     
CODE..................................................................................................................................................
#include<iostream.h>
#include<conio.h>
class emp //emp - employer
{
            protected : // protected is used so that only manager class can only access the emp class
            int i ;
            char name [30] ;
            float sal ; // sal for salary
} ;
class manger : public emp
{
            float perf_bonus ; // perf-bonus means performance bonus
            flost total_bonus ; //total_bonus means all bonus are added in one
            public :
                         void input ( )
                         {
                                    cout<<"id,name,sal,bonus" ;
                                    cin>>id>>name>>sal>>perf_bonus ;
                         }
                         void display ( )
                         {
                                    cout<<"id ="<<id<<"name ="<<name<<"sal ="<<sal<<"performance                                                  bonus="<<perf_bonus <<endl ;
                                    total_sal =sal + perf_bonus ;
                                    cout<<"total salary ="<<total_salary<<endl ;
                         }
} ;
void main ( )
{
           manager m ;
           m.input ( ) ;
           m.display ( ) ;
           getch ( ) ; 
}

END........................................................................................................................................................
                                    !!!!!!!!! THANKS FOR TIME !!!!!!!!!!
and for more like this article follow us and i have given the link above .
any doubt regarding this article write in the comment box 

About hack guru

hack guru
Recommended Posts × +

0 comments:

Post a Comment