Write a program that starts with a base class employee. This class contains employee’s name and employee number. From this class inherit three other classes which are manager, scientist and laborer. The manager and scientist classes should contain additional information about these categories of employee and member functions. Override the methodwhich calculate salary of employee in its each child class.

Write a program that starts with a base class employee. This class contains employee’s name and employee number. From this class inherit three other classes which are manager, scientist and laborer. The manager and scientist classes should contain additional information about these categories of employee and member functions.

Override the methodwhich calculate salary of employee in its each child class.


Solution

#include<iostream>

#include<string>

using namespace std;

class employee{

 

 

public:

string First_name, Last_name;

long long int P_number;

    int per_hour;

virtual void calculate_salary() = 0;

 

};

class manager :public employee

{

string company_name;

public:

manager()

{

First_name = "Muhammad";

Last_name = "Irfan";

P_number = 3116626732;

company_name = "Microsoft";

}

void Display_manager();

void calculate_salary();

};

class scientist :public employee{

 

string company_name;

public:

scientist()

{

First_name = "Muhammad";

Last_name = "Ahmad";

P_number = 3445533432;

company_name = "NASA";

}

void Display_scientist();

void calculate_salary();

 

 

};

class labor :public employee{

public:

 

labor()

{

First_name = "Irfan";

Last_name = "Khan";

P_number = 3123577856;

 

}

void Display_labor();

void calculate_salary();

 

};

 

void manager::Display_manager()

{

cout << "\t\tHello There, I am a Manager " << endl;

cout << "...................................................." << endl;

cout << "\tName\t\t : " << First_name << " " << Last_name << endl;

cout << "\tNumber\t\t : " << P_number << endl;

cout << "\tCompany Name\t : " << company_name << endl;

 

}

void manager::calculate_salary()

{

cout<<"\tPer_Day Rate     : ";

cin>>per_hour;

cout << "\tMonthly Salary   : "<<per_hour*30 << endl;

cout << endl;

cout << "...................................................." << endl;

}

// defination of scientist member function

void scientist::Display_scientist()

{

cout << "\t\tHello There, I am a Scientist " << endl;

cout << "...................................................." << endl;

cout << "\tName \t\t: " << First_name << " " << Last_name << endl;

cout << "\tNumber\t\t: " << P_number << endl;

cout << "\tCompany Name    : " << company_name << endl;

}

void scientist::calculate_salary()

{

cout<<"\tPer_Day Rate    : ";

cin>>per_hour;

cout << "\tMonthly Salary  : "<<per_hour*30 << endl;

cout << endl;

cout << "...................................................." << endl;

}

void labor::Display_labor()

{

cout << "\t\tHello There , I am a labor" << endl;

cout << "...................................................." << endl;

cout << "\tName \t\t: " << First_name << " " << Last_name << endl;

cout << "\tNumber \t\t: " << P_number << endl;

}

void labor::calculate_salary()

{

cout<<"\tPer_Day Rate    : ";

cin>>per_hour;

cout << "\tMonthly Salary  : "<<per_hour*30 << endl;

}

int main()

{

employee  *ptr;

manager m1;

scientist s1;

labor l1;

m1.Display_manager();

ptr = &m1;

ptr->calculate_salary();

s1.Display_scientist();

ptr = &s1;

ptr->calculate_salary();

l1.Display_labor();

ptr = &l1;

ptr->calculate_salary();

}


Output
Write a program that starts with a base class employee. This class contains employee’s name and employee number. From this class inherit three other classes which are manager, scientist and laborer. The manager and scientist classes should contain additional information about these categories of employee and member functions.  Override the methodwhich calculate salary of employee in its each child class.



 random/hot-posts 

PROGRAMMING QUESTIONS/feat-big

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.