Write a C program using multiple functions that will calculate the gross pay for a set of employees
Write a C program using multiple functions that will calculate the gross pay for a set of employees
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 shown below. Column alignment, leading zeros in Clock number, and zero suppression in float fields is important. Use 1.5 as the overtime pay factor.
--------------------------------------------------------------------------_x000D_
Clock# Wage Hours OT Gross_x000D_
--------------------------------------------------------------------------_x000D_
098401 10.60 51.0 11.0 598.90_x000D_
526488 9.75 42.5 2.5 426.56_x000D_
765349 10.50 37.0 0.0 388.50_x000D_
034645 12.25 45.0 5.0 581.88_x000D_
127615 8.35 0.0 0.0 0.00_x000D_
_x000D_
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.
- Try to limit how much code you have in your main function, call other functions to do the work that is needed.
- 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. Note that a function comment header is not needed for your main function.
- Feel free to initialize the clock and wage values into your arrays with the test data above.
- DO NOT pre-fill 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.
#include <stdio.h>
/* constants */
#define NUM_EMPL 5
#define OVERTIME_RATE 1.5f
#define STD_WORK_WEEK 40.0f
/* function prototypes */
/* I added one below to get you started */
float getHours (long clockNumber);
void printData (long int clockNumber[], float wageRate[], float hours[],
float overtime[], float gross[], int size);
/* IMPORTANT: Add other function prototypes here as needed */
int main()
{
/* Variable Declarations */
long int clockNumber[NUM_EMPL] = {98401,526488,765349,34645,127615}; /* unique ID */
float gross[NUM_EMPL]; /* gross pay */
float hours[NUM_EMPL]; /* hours worked in a given week */
int i; /* loop and array index */ float overtime[NUM_EMPL]; /* overtime hours */
float wageRate[NUM_EMPL] = {10.60,9.75,10.50,12.25,8.35}; /* hourly wage rate */
for (i = 0; i < NUM_EMPL; ++i) {
/* Function call to get input from user. */
hours[i] = getHours (clockNumber[i]);
/* Function call to calculate overtime */
/* Function call to calculate gross pay */
} /* Print the header info */
/* Print all the employees – call by reference */ printData (clockNumber, wageRate, hours, overtime, gross, NUM_EMPL);
return (0);
}
//**************************************************************/
// Function: getHours
//
// Purpose: Obtains input from user, the number of hours worked
// per employee and stores the result in an local variable
// that is passed back to the calling function.
//
// Parameters: clockNumber – The clock number of the employee
//
// Returns: hoursWorked – hours worked by the employee in a given week (call by value)
//
//**************************************************************/
float getHours (long int clockNumber)
{
float hoursWorked; /* hours worked in a given week */
/* Get Hours for each employee */
printf(“nEnter hours worked by emp # %06li: “, clockNumber);
scanf (“%f”, &hoursWorked);
return (hoursWorked);
}
//**************************************************************/
// Function: printData
//
// Purpose: Prints out all the employee information in a
// nice and orderly table format.//
// Parameters:
//
// clockNumber – Array of employee clock numbers
// wageRate – Array of employee wages per hour
// hrs – Array of number of hours worked by an employee
// overtime – Array of overtime hours for each employee
// gross – Array of gross pay calculations for each employee
// size – Number of employees to process
//
// Returns: Nothing (call by reference)
//
//**************************************************************/
void printData (long int clockNumber[], float wageRate[], float hours[],
float overtime[], float gross[], int size){
/* This is an example of a “Stub” … you need to add code … */
/* but you can set up and call it and fill in the details later */
/* Add a loop here and print information on each employee */
/* in a nice orderly table, just like you have done before */
/* HINT: The loop and code setup is similar to how the getInput */
/* function is implemented in the alternate template (by reference)*/
}
/* Add other functions here as needed */
/* … remember your comment block headers for each function */
"You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.
Discount Code: CIPD30
Click ORDER NOW..


