Write a C++ Program ,
· Create a structure called Employee that includes employee ID (string), name of the employee (string), over-time fee (float) and the number of over-time hours during the weekdays (int array).
· Write a function called getEmp( ) which is the data type of Employee that reads the details of Employee and store them in the variable of the Employee structure.
Employee getEmp(Employee e);
· Write a function called calOTpayment( ) which takes three parameters, over-time fee of the employee, number of over-time hours in weekdays (5 days) array and the size of the array. Find the total payment for the employee and print the total Over-time fee for Weekdays.
· Call the getEmp( ) and calOTpayment( ) functions in the main function to print the following output as required.
#include <iostream>
struct Employee {
std::string id;
std::string name;
float fee;
int hours[5];
};
Employee getEmp(Employee e)
{
Employee emp;
emp.id = e.id;
emp.name = e.name;
emp.fee = e.fee;
emp.hours = e.hours;
return emp;
}
float calOTpayment(float fee, int * hours, int n)
{
float total = 0;
for (int i = 0; i < n; i++) {
total += fee * hours[i];
}
return 0;
}
int main()
{
Employee e;
e.id = "34ef-k345-kh43-k3h5";
e.name = "John";
e.fee = 4.5;
e.hours = [4, 5, 14, 12, 7];
Employee emp = getEmp(e);
std::cout << calOTpayment(emp.fee, emp.hours, 5);
return 0;
}
Comments
Leave a comment