Answer:
The cpp program for the scenario is shown.
#include <iostream>
using namespace std;
int main() {
int count;
int empNum[count];
double work_hrs[count];
double hrly_wage[count];
double ot_wage[count];
double hour = 40.00;
double gross_pay[count];
double tax=3.625;
double total_pay = 0, avg_pay;
cout<<"Enter the number of employees "<<endl;
cin>>count;
cout<<"Enter the details for the employees "<<endl;
int i=0;
while(i<count)
{
cout<<"Enter the id"<<endl;
cin>>empNum[i];
cout<<"Enter the working hours"<<endl;
cin>>work_hrs[i];
cout<<"Enter the hourly pay"<<endl;
cin>>hrly_wage[i];
ot_wage[i] = hrly_wage[i]*1.5;
i++;
}
cout<<"The payroll for the employees "<<endl;
i=0;
while(i<count)
{
if(work_hrs[i] > hour)
gross_pay[i] = ( hour*hrly_wage[i] );
else
gross_pay[i] = ( hrly_wage[i]*work_hrs[i] );
if(work_hrs[i] > hour)
gross_pay[i] = gross_pay[i] + ( (work_hrs[i]-hour)*ot_wage[i] );
gross_pay[i] = gross_pay[i]-( (gross_pay[i]*tax)/100 );
total_pay = total_pay + gross_pay[i];
i++;
}
avg_pay = total_pay/count;
i=0;
while(i<count)
{
cout<<"Gross pay of employee "<<empNum[i]<<" : "<<gross_pay[i]<<endl;
i++;
}
cout<<"Average amount paid to all employees is "<<avg_pay<<endl;
return 0;
}
OUTPUT
Enter the number of employees
2
Enter the details for the employees
Enter the id
111
Enter the working hours
46
Enter the hourly pay
12
Enter the id
222
Enter the working hours
50
Enter the hourly pay
14
The payroll for the employees
Gross pay of employee 111 : 566.685
Gross pay of employee 222 : 742.087
Average amount paid to all employees is 654.386
Step-by-step explanation:
1. User enters the number of employees.
2. User enters all pieces of information including identification number, hourly wage rate and number of hours worked.
3. Inside a while loop, user input is taken in the arrays.
4. Inside another while loop, the gross pay of each employee is computed. The gross pay of each employee is added to the variable, total_pay.
5. The value of the variable, avg_pay, is computed outside the loop.
6. All the while loops work over variable i till the value of i becomes 1 less than count.
7. The value of the variable, i, is made 0 before the loop begins.
8. The employee number and the gross pay of each employee is displayed followed by the average pay.