Answer to Question #289243 in C++ for Highping

Question #289243

Write a C++ program by creating an 'Employee' class having the following functions and print the

final salary.

1 - 'getInfo()' which takes the salary, number of hours of work per day of employee as

parameters

2 - 'AddSal()' which adds $10 to the salary of the employee if it is less than $500.

3 - 'AddWork()' which adds $5 to the salary of the employee if the number of hours of work per

day is more than 6 hours.


1
Expert's answer
2022-01-20T16:16:08-0500
#include<iostream>


using namespace std;


class Employee
{
	double salary;
	int no_of_hours;
public:
	Employee() {}
	void getinfo()
	{
		cout << "Please, enter the salary of employee: ";
		cin >> salary;
		cout << "Please, enter the number of hours: ";
		cin >> no_of_hours;
	}
	void AddSal()
	{
		if (salary < 500)
			salary += 10;
	}
	void AddWork()
	{
		if (no_of_hours > 6)
			salary += 5;
	}
	void DisplaySalary()
	{
		cout << salary;
	}


};


int main()
{
	int num;
	cout << "Enter the number of employees: ";
	cin >> num;
	Employee* emp=new Employee[num];
	for (int i = 0; i < num; i++)
	{
		emp[i].getinfo();
		emp[i].AddSal();
		emp[i].AddWork();
	}
	for (int i = 0; i < num; i++)
	{
		cout << "\nThe final salary of employee "<<i<<" is:";
		emp[i].DisplaySalary();
	}
}

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