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

In this assignment I cant use structures, Only functions. HOMEWORK 4 FUNCTIONS W

ID: 641761 • Letter: I

Question

In this assignment I cant use structures, Only functions.

HOMEWORK 4
FUNCTIONS

Write a C program using multiple functions that will calculate the gross pay for a set of employees.

See the last lecture note this week for a template you can use if you feel you need something to start with. However, feel free to implement this assignment that way you see fit, the template is just there if you need it. There are multiple ways to effectively implement this assignment.

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 number, 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


Use the following clock and wage information to initialize your data, clock#, wage


     98401 10.60  
    526488   9.75
    765349 10.50
     34645 12.25
    127615   8.35

You should implement this program using one array for clock number, one array for wage rate, etc.

Read in the hours worked for each employee

Limit your use of global variables - Learn how to pass parameters!

You should have at least 3-4 functions designed and implemented in addition to the main function.

Remember to use constants and all the other things we have covered up to this assignment

Re-read the homework coding standards ... make sure that each local variable is commented in EACH function, and EACH function has a descriptive function comment header

Feel free to initialize the clock and wage values into your arrays with the test data above

DO NOT prefill the hours, overtime, and gross pay arrays with test data values. It is OK however to initialize them to zero if you wish, but it is not needed since these values get overwritten via input prompts or calculations.

I would recommend that your clock, wage, hours, overtime, and gross values be stored in individual arrays. As a challenge, you can have your program prompt the user to enter the number of hours each employee worked. When prompted, key in the hours shown below.

Do define your array size up front in your variable declaration. Don't define the array size at run time with a variable. This strategy does not always work on every C compiler.

Create a separate function whenever possible to break up your program. For instance, you might have a function for obtaining the hours from the user, another function for calculating overtime hours, another for calculating gross pay and another function for producing the output. At a minimum, you should have a main function and three or more other functions.

Finally, as always, don't use concepts we have not yet covered.

Here's what i have

#include

struct employee

{

long int clock_num; // /* employee clock number */

float hours; // /* number of hours worked per week */

float gross; // /* gross pay for week (wage * hours) */

float wage; // /* hourly wage */

float over_time; // /* overtimne */

};

int main()

{

struct employee array[] = {{98401, 10.60},

{526488, 9.75},

{765349, 10.50},

{34645, 12.25},

{127615, 8.35}};

int i;

for(i=0; i<5; i++)

{

printf(" Enter the number of hours employee %d worked: ",(i+1));

scanf("%f",&array[i].hours);

if(array[i].hours>40)

{

array[i].over_time = (array[i].hours-40);

array[i].gross = array[i].over_time*1.5*array[i].wage + 40*array[i].wage;

}

else

{

array[i].over_time = 0;

array[i].gross = array[i].hours*array[i].wage;

}

}

/* print out employee information */

printf (" Corey, C Programming, Assignment 4 ");

printf(" --------------------------------------------------------------------------");

printf(" Clock# Wage Hours OT Gross");

printf(" --------------------------------------------------------------------------");

for(i=0; i<5; i++)

{

printf(" %06d %.2f %.1f %.1f %.2f",array[i].id_number,array[i].wage,array[i].hours,array[i].overtime,array[i].gross);

}

return 0;

}

Explanation / Answer

/*-------------------------------------------------------------------------------- ** ** HOMEWORK: #5 Structures ** ** ** Description: This program prompts the user for the number of hours ** worked for each employee. It then calculates gross pay ** including overtime and displays the results in table. Functions ** and structures are used. **-------------------------------------------------------------------------------*/ /*Define and Includes */ #include /* Define Constants */ #define NUM_EMPL 5 #define OVERTIME_RATE 1.5f #define STD_HOURS 40.0f /* Define a global structure to pass employee data between functions */ /* Note that the structure type is global, but you don't want a variable */ /* of that type to be global. Best to declare a variable of that type */ /* in a function like main or another function and pass as needed. */ struct employee { long id_number; float wage; float hours; float overtime; float gross; }; /* define prototypes here for each function except main */ void Get_input (struct employee [ ], int size); void Overtime_calc (struct employee [ ], int size); void Output_results_screen (struct employee [ ], int size); /*----------------------------------------------------------------------- ** Function: Get_input ** ** Purpose: Obtains input from user for the number of hours worked per ** employee, and stores the results in an array of structures that is ** passed back to the calling program by reference. ** ** Parameters: employeeData - an array of structures containing ** employee information ** size - number of employees to process ** ** Returns: Nothing (void) ** -----------------------------------------------------------------------*/ void Get_input (struct employee employeeData[], int size) { /*Local Variable Declaration */ int i; /* Loop index */ /* Gets number of employee hours and stores them in the array. */ for (i = 0; i