Answer to Question #252957 in C++ for Jaganathan

Question #252957
Define the classes using hierarchy inheritance. An organization has two types of employees: Regular and Adhoc are derived class. Regular employees get a salary which is Basic salary + DA + HRA where DA is 10% of basic and HRA is 30% of basic. Adhoc employees are daily wagers who get a salary which is equal to Number oh hours * Wages amount. The employee base class consisting of member variables such as name and empid. When a regular employee is created, basic salary must be a parameter. When Adhoc employee is created wages amount must be a parameter. Define the member functions for each class and the member function days( ) updates number of the Adhoc employee.
1
Expert's answer
2021-10-18T18:28:00-0400
#include <iostream>
#include <string>
using namespace std;


class Employee{
    private:
    	string name;
    	int empid;
    public:
    	Employee(){
    	}
    	virtual float salary(){
    		return 0;
    	}
    	void setName(string n){
    		name=n;
    	}
    	void setEmpid(int id){
    		empid=id;
    	}
};




class Regular :public Employee{
    private:
    	float basic_salary;
    public:
    	Regular(float bs){
    		basic_salary=bs;
    	}
    		float salary(){
    		float DA=basic_salary*0.1;
    		float HRA=basic_salary*0.3;
    		return basic_salary+ DA + HRA;
    	}
};


class Adhoc:public Employee{
    private:
    	int num;
    	float wages_amount;
    public:
    	Adhoc(float wa){
    		wages_amount=wa;
    	}
    	float salary(){
    		return num*wages_amount;
    	}
    	void days(int n){
    		this->num=n;
    	}
};
int main(){
	Regular r(10000);
	r.setName("John");
	r.setEmpid(1234);
	cout<<"The salary of Regular employee: "<<r.salary()<<endl;
	Adhoc ad(20);
	ad.setName("Joan");
	ad.setEmpid(5678);
	ad.days(7);
	cout<<"The salary of Adhoc employee: "<<ad.salary()<<"\n";
	return 0;
}

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