#include<iostream>
using namespace std;
class Employee //here i make the base class name Employee
{
protected:
string name;
int number;
public:
Employee() //here i make a default constructor
{
name="";
number=0;
}
virtual void info(string x,int y) //here i make a function for overriding
{
name=x;
number=y;
cout<<"the name of the employee is:"<<name<<endl;
cout<<"the number of the employee is:"<<number<<endl;
}
virtual void salary(double x) //here i make a function for overriding
{
double s;
s=x;
cout<<"salary of the employee is:"<<s<<endl;
}
};
class Manager:public Employee //here i make a child class name Manager
{
private:
string manager_address,manager_education;
int manager_age;
public:
void info(string x,int y) //here function overriding
{
name=x;
number=y;
cout<<"the name of the manager is:"<<name<<endl;
cout<<"the number of the manager is:"<<number<<endl;
}
void salary(double x) //here function overriding
{
double s;
s=x;
cout<<"salary of the manager is:"<<s<<endl;
}
void getmanagerInfo(string x,string y,int z) //function that get information
{
manager_address=x;
manager_education=y;
manager_age=z;
}
void setmanagerInfo() //function that set information
{
cout<<"the address of the manager is:"<<manager_address<<endl;
cout<<"the education of the manager is:"<<manager_education<<endl;
cout<<"the age of the manager is:"<<manager_age<<endl;
}
};
class scientist:public Employee //here i make a child class name scientist
{
private:
string scientist_address,scientist_education;
int scientist_age;
public:
void info(string x,int y) //here function overriding
{
name=x;
number=y;
cout<<"the name of the scientist is:"<<name<<endl;
cout<<"the number of the scientist is:"<<number<<endl;
}
void salary(double x) //here function overriding
{
double s;
s=x;
cout<<"salary of the scientist is:"<<s<<endl;
}
void getscientistInfo(string x,string y,int z) //function that get information
{
scientist_address=x;
scientist_education=y;
scientist_age=z;
}
void setscientistInfo() //function that set information
{
cout<<"the address of the scientist is:"<<scientist_address<<endl;
cout<<"the education of the scientist is:"<<scientist_education<<endl;
cout<<"the age of the scientist is:"<<scientist_age<<endl;
}
};
class laborer:public Employee //here i make a child class name laborer
{
private:
string laborer_address;
int laborer_age;
public:
void info(string x,int y) //here function overriding
{
name=x;
number=y;
cout<<"the name of the laborer is:"<<name<<endl;
cout<<"the number of the laborer is:"<<number<<endl;
}
void salary(double x) //here function overriding
{
double s;
s=x;
cout<<"salary of the laborer is:"<<s<<endl;
}
void getlaborerInfo(string x,int z) //function that get information
{
laborer_address=x;
laborer_age=z;
}
void setlaborerInfo() //function that set information
{
cout<<"the address of the laborer is:"<< laborer_address<<endl;
cout<<"the age of the laborer is:"<< laborer_age<<endl;
}
};
int main()
{
Employee obj1;
Employee *ptr;
Manager obj2;
scientist obj3;
laborer obj4;
cout<<"\t\t\tEmployee class..."<<endl;
cout<<endl;
obj1.info("hamza",18);
obj1.salary(45000);
cout<<"\t\t\tmanager class..."<<endl;
cout<<endl;
ptr=&obj2;
ptr->info("hassan",5017);
ptr->salary(30000);
obj2.getmanagerInfo("isa-khel","BSCS",25);
obj2.setmanagerInfo();
cout<<"\t\t\tscientist class..."<<endl;
cout<<endl;
ptr=&obj3;
ptr->info("hammad",4718);
ptr->salary(40000);
obj3.getscientistInfo("mainwali","BSse",17);
obj3.setscientistInfo();
cout<<"\t\t\tlaborer class..."<<endl;
cout<<endl;
ptr=&obj4;
ptr->info("hamza-rehman",4718);
ptr->salary(600000);
obj4.getlaborerInfo("mainwali",30);
obj4.setlaborerInfo();
}
No comments:
Post a Comment