INHERITANCE
#include <iostream>
#include <string.h>
//#include <stdio.h>
using namespace std;
int z=101;
int c=0;
class emp
{ static int n;
int eid, salary;
char nm[10];
public :
emp()
{
c++;
eid=n++;
salary=0;
strcpy (nm,"no_name");
}
emp(char *name, int s)
{
c++;
eid=n++;
strcpy (nm, name);
salary=s;
}
static void id(int a)
{
n=a;
}
void setnm(char* a)
{strcpy(nm, a);}
void sets(int s)
{salary=s;}
char* getnm()
{return nm;}
int gets()
{return salary;}
int geteid()
{return eid;}
void employee(char *m, int s)
{
strcpy (nm, m);
salary=s;
}
void display()
{
cout<<"\n employees id is :"<<eid;
cout<<"\n employees name is :"<<nm;
cout<<"\n employees salary is :"<<salary<<"\n";
}
};
class Salesmanager : public emp
{
int target;
int incentive;
public :
Salesmanager():emp()
{
target=0;
incentive=0;
}
Salesmanager(char* nm,int s,int t,int in):emp(nm,s)
{
target=t;
incentive=in;
}
void setTarget(int t)
{
}
int getTareget()
{
return target;
}
void setIncentive(int i)
{
incentive=i;
}
int getIncentive()
{
return incentive;
}
void display()
{
emp ::display();
cout << "\n target is : "<<target;
cout<< "\n incentive is : "<< incentive;
}
};//Salemanager ends here
class admin : public emp
{
int allowence;
public:
admin()
{
allowence=0;
}
admin(char *nm, int s,int all):emp(nm,s)
{
allowence=all;
}
void setall(int a)
{
allowence=a;
}
int setall()
{
return allowence;
}
void display()
{
emp ::display();
cout << "\n allowence is : "<<allowence;
}
};
}
void main()
{
Employee* ep;
Employee e1(101,"sachin",2000);
ep=&e1
ep->display();
Salesmanager s1(102,"sachin",2000,200,20);
ep=&s1
ep->display();
s1.setName("Sachin");
s1.display();
Salesmanager s2(102,"Ashutosh",15000,5000,500);
s2.display();
s2.setSal(25000);
s2.display();
}
#include <string.h>
//#include <stdio.h>
using namespace std;
int z=101;
int c=0;
class emp
{ static int n;
int eid, salary;
char nm[10];
public :
emp()
{
c++;
eid=n++;
salary=0;
strcpy (nm,"no_name");
}
emp(char *name, int s)
{
c++;
eid=n++;
strcpy (nm, name);
salary=s;
}
static void id(int a)
{
n=a;
}
void setnm(char* a)
{strcpy(nm, a);}
void sets(int s)
{salary=s;}
char* getnm()
{return nm;}
int gets()
{return salary;}
int geteid()
{return eid;}
void employee(char *m, int s)
{
strcpy (nm, m);
salary=s;
}
void display()
{
cout<<"\n employees id is :"<<eid;
cout<<"\n employees name is :"<<nm;
cout<<"\n employees salary is :"<<salary<<"\n";
}
};
class Salesmanager : public emp
{
int target;
int incentive;
public :
Salesmanager():emp()
{
target=0;
incentive=0;
}
Salesmanager(char* nm,int s,int t,int in):emp(nm,s)
{
target=t;
incentive=in;
}
void setTarget(int t)
{
}
int getTareget()
{
return target;
}
void setIncentive(int i)
{
incentive=i;
}
int getIncentive()
{
return incentive;
}
void display()
{
emp ::display();
cout << "\n target is : "<<target;
cout<< "\n incentive is : "<< incentive;
}
};//Salemanager ends here
class admin : public emp
{
int allowence;
public:
admin()
{
allowence=0;
}
admin(char *nm, int s,int all):emp(nm,s)
{
allowence=all;
}
void setall(int a)
{
allowence=a;
}
int setall()
{
return allowence;
}
void display()
{
emp ::display();
cout << "\n allowence is : "<<allowence;
}
};
}
void main()
{
Employee* ep;
Employee e1(101,"sachin",2000);
ep=&e1
ep->display();
Salesmanager s1(102,"sachin",2000,200,20);
ep=&s1
ep->display();
s1.setName("Sachin");
s1.display();
Salesmanager s2(102,"Ashutosh",15000,5000,500);
s2.display();
s2.setSal(25000);
s2.display();
}
Comments
Post a Comment