Answer to Question #213206 in C++ for Hemambar

Question #213206

Create a class called Employee with protected data members emp_id, name and designation. It

contains the member functions to get details of employee and display them. Derive two classes

Permanent and Contract from Employee class. Contract has data members num_hrs and

wages_per_hr. Permanent has basic, DA, TA and HRA. Get the necessary details using member

functions and display the employee details with their salary according to the given data.


1
Expert's answer
2021-07-24T07:02:56-0400
#include<iostream>
using namespace std;
class Employee{
	protected:
		int  emp_id;
		string name;
		string designation;
	public:
		void input_Employee_details(){
			cout<<"Employee id\n";
			cin>>emp_id;
			cout<<"Employee name\n";
			cin>>name;
			cout<<"Employee designation\n";
			cin>>designation;
		}
		void display_details(){
			input_Employee_details();
			cout<<"Employee id is\t"<<emp_id;
			cout<<"Employee name is\t"<<name<<endl;
			cout<<"Employee designation is\t"<<designation<<endl;
		}
};
class Permanent: public Employee{
	private:
		double basic;
		double DA;
		double TA;
		double HRA;
	public:
		void input_permanet(){
			cout<<"Employee basic \t\n";
			cin>>basic;
			cout<<"Employee DA \n";
			cin>>DA;
			cout<<"Employee TA\n";
			cin>>TA;
			cout<<"Employee HRA\n";
			cin>>HRA;
		}
		void total_salary(){
			input_permanet();
			display_details();
			cout<<"Employee basic \t"<<basic;
			
			cout<<"\nEmployee DA \t"<<DA;
			
			cout<<"\nEmployee TA\t"<<TA;
			
			cout<<"\nEmployee HRA\t"<<HRA;
			
			cout<<"\nEmployee Salary is\t"<<basic + DA+TA+HRA<<endl;
		}
	
}; 
class Contract: public Employee{
	private:
		int  num_hrs;
		double wages_per_hr;
	public:
		void input_contract(){
			cout<<"Employee number of hours\n";
			cin>>num_hrs;
			cout<<"Employee wages per hour\n";
			cin>>wages_per_hr;
		}
	 void display_contract(){
	 	input_contract();
	 	display_details();
	 		cout<<"\nEmployee number of hours\t"<<num_hrs;
			cout<<"\nEmployee wages per hour\t"<<wages_per_hr;
	 	cout<<"\nEmployee salary is \t"<<num_hrs * wages_per_hr;
	 }
}; 
int main(){
	Contract c;
	Permanent per;
	c.display_contract();
	cout<<"\n";
	per.total_salary();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS