Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

p.287 Programming Project 7. Write a program to process weekly employee time car

ID: 3625564 • Letter: P

Question

p.287 Programming Project 7. Write a program to process weekly employee time cards for all employees of an organization. Each employee will have 3 data items: an identification number, the hourly wage rate, and the number of hours worked during a given week. Each employee is to be paid time and ahalf for all hours worked over 40 hours. A tax amount of 3.625 percent of gross salary will be deducted. The program output should show the employee's number and net pay. Display the total payroll and the average amount paid at the end of the run.

Assume that the data is coming from a file. Test the program with the following data set:

101 7.50 44
102 6.00 30
103 8.50 40
105 12.00 48

Explanation / Answer

#include<stdio.h>

void main()

{

    FILE *fd;

     int i=1;

     int id,hrs;

     float rate,pay,avg=0;

     if((fd=fopen("EmpData.txt","r"))==NULL)

     {

       perror("fopen");

        exit(1);

     }

     while(fscanf(fd,"%d %f %d ",id,rate,hrs)!=EOF)

     {

         if(hrs<=40)

              pay=hrs*rate;

          else

           pay=(hrs*rate)*0.0362;

          avg+=pay;

          i++;

          printf("EmpID:%dPay=%f",id,pay);

     }

     avg=avg/i;

     printf("Average pay:%f",avg);

}//end main