Write a C++ Program to do the following. • Create a structure called Employee that includes employee ID (string), name of the employee (string), the over-time fee (float) and the number of overtime hours during the weekdays (int aray). • 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. Hint: Use the given function prototype as 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 Overtime fee for Weekdays. • Call the getEmp() and calOTpayment() in the main function to print the following output as required.
#include <iostream>
#include <string>
using namespace std;
struct Employee {
string ID;
string name;
float overtimeFee;
int overtimHours[5];
};
Employee getEmp(Employee e) {
cout << "Get an employee ID: ";
cin >> e.ID;
cin.ignore();
cout << "Get a name of the employee: ";
getline(cin, e.name);
cout << "Get overtime fee: ";
cin >> e.overtimeFee;
cout << "Enter the number of overtime hours:" << endl;
for (int i=0; i<5; i++) {
cout << "Day " << i+1 << ": ";
cin >> e.overtimHours[i];
}
return e;
}
float calOTpayment(float fee, int hours[], int size) {
double payment = 0.0;
for (int i=0; i<size; i++) {
payment += fee*hours[i];
}
return payment;
}
int main() {
Employee e;
e = getEmp(e);
double payment = calOTpayment(e.overtimeFee, e.overtimHours, 5);
cout << endl << "Overtime payment for " << e.name
<< " is $" << payment << endl;
return 0;
}
Comments
Leave a comment