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

Write a C program that will calculate the gross pay of a set of employees. The p

ID: 673540 • Letter: W

Question

Write a C program that will calculate the gross pay of a set of employees.

The program should prompt the user to enter the number of hours each employee worked. When prompted, key in the hours shown below.

The program determines the overtime hours (anything over 40 hours), the gross pay, and then outputs a table in the following format. Column alignment, leading zeros in Clock#, and zero suppression in float fields is important. Use 1.5 as the overtime pay factor.

    --------------------------------------------------------------------------

        Clock#   Wage Hours      OT     Gross

    --------------------------------------------------------------------------

        098401 10.60   51.0    11.0    598.90

        526488   9.75   42.5     2.5    426.56

        765349 10.50   37.0     0.0    388.50

        034645 12.25   45.0     5.0    581.88

        127615   8.35    0.0     0.0      0.00

You should implement this program using the following structure to store the information for each employee.

    /* This is the structure you will need, feel free to modify as needed */

    struct employee

    {

          long int id_number; /* or just int id_number; */

          float wage;

          float hours;

          float overtime;

          float gross;

    };

In your main function, define an array of structures, and feel free to initialize the clock and wage values in your array declaration. You must prompt for each employee's hours and calculate their corresponding overtime and gross pay.

Use the following information to initialize your data.

    98401   10.60  

    526488   9.75

    765349 10.50

    34645   12.25

    127615   8.35

Separate your code into functions to get the hours from the user, calculate the over time, calculate the gross and print the data to the screen.

Create an array of structures with 5 elements, each being of type struct employee. Initialize the array with the data provided and reference the elements of the array with the appropriate subscripts.   Like the previous homework, use multiple functions in your answer and continue to use constants as needed.    The only array you need is the array of structures, you don't need to create a separate array for clock, wage, hours, overtime, and gross.   You can either pass the entire array of structures to each function, or pass values that work on one array element (and its associated structure members) at a time ... either will work.

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>
struct employee{
long int id_number;
float wage;
float hours;
float overtime;
float gross;
};
void getHours(struct employee []);
void calOverTime(struct employee []);
void calGross(struct employee [] );
void printData(struct employee []);
int main(){
   struct employee e[5]={{98401,10.60},{526488,9.75},{765349,10.50},{34645,12.25},{127615,8.35}};
   getHours(e);
   calOverTime(e);
calGross(e);
   printData(e);
}
void getHours(struct employee e1[]){
   int i=1;
   printf(" Enter Hours for 5 employees ");
   for(i=0;i<5;i++){
       scanf("%f",&e1[i].hours);
   }
}
void calOverTime(struct employee e1[]){
   int i;
   for(i=0;i<5;i++){
       if(e1[i].hours > 40){
           e1[i].overtime=e1[i].hours-40;
       }
       else {
           e1[i].overtime=0.0;
       }
   }
}
void calGross(struct employee e1[] ){
   int i;
   for(i=0;i<5;i++){
       if(e1[i].overtime!=0.0){
               e1[i].gross= e1[i].wage*(e1[i].hours-e1[i].overtime)+ e1[i].wage*e1[i].overtime*1.5;
       }else{
           e1[i].gross= e1[i].wage*e1[i].hours;
       }
  
   }
}
void printData(struct employee e1[]){
   int i;
   printf("_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ");
   printf(" CLOCK# Wage Hours OT Gross ");
   printf("_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ");
   for(i=0;i<5;i++){
       printf(" %ld %0.2f %0.1f %0.1f %0.2f ",e1[i].id_number,e1[i].wage,e1[i].hours,e1[i].overtime,e1[i].gross);
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote