Write a C++ program by creating an 'Employee' 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.
class Employee
{
public:
int salary;
int hours_of_work;
Employee(int s, int h_o_w) : salary(s), hours_of_work(h_o_w) {}
void getInfo()
{
std::cout << "Salary - " << salary << std::endl;
std::cout << "The number of hours of work per day - " << hours_of_work << std::endl;
}
void AddSal()
{
if (salary < 500)
{
salary += 10;
}
}
void AddWork()
{
if (hours_of_work > 6)
{
salary += 5;
}
}
};
Comments
Leave a comment