Answer to Question #179180 in C++ for Ajith

Question #179180

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-04-07T11:44:29-0400
#include <iostream>
#include <string>
 
using namespace std;
 
class Employee
{
public:
	Employee(string name, int id_);
protected:
	string name;
	int id;
};
 
Employee::Employee(string name_, int id_) : name(name_), id(id_)
{}
 
class Regular : public Employee
{
public:
	Regular(string name_, int id_, double salary_);
	void Display();
private:
	double salary;
	double DA = 0.1;
	double HRA = 0.3;
};
 
Regular::Regular(string name_, int id_, double salary_) : Employee(name_, id_), salary(salary_)
{}
 
void Regular::Display()
{
	cout << "Name is: " << name << endl;
	cout << "Employee ID is: " << id << endl;
	cout << "Employee salary is: $" << salary * (1 + DA + HRA) << endl;
}
 
class Adhoc : public Employee
{
public:
	Adhoc(string name_, int id_, double wages_);
	int Days(int days);
	void Display();
private:
	double wages;
};
 
Adhoc::Adhoc(string name_, int id_, double wages_) : Employee(name_, id_), wages(wages_)
{}
 
int Adhoc::Days(int days)
{
	return days * 8;		// hours in month
}
 
void Adhoc::Display()
{
	int days;
	cout << "Enter how many days " << name << " worked: ";
	cin >> days;
	cout << "Name is: " << name << endl;
	cout << "Employee ID is: " << id << endl;
	cout << "Employee salary is: $" << wages * Days(days) << endl;
}
 
int main()
{
	Regular Mike("Mike", 12, 10000);
	Mike.Display();
	cout << "************************************************" << endl;
	Adhoc Brian("Brian", 18, 35);
	Brian.Display();
	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