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.
#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();
}
}
Comments
Leave a comment