/* Homework: 4 */
/* */
/* Name: Susie Smith */
/* */
/* Class: C Programming, Fall 2019 */
/* */
/* Date: 10/06/19 */
/* */
/* Description: Program which determines gross pay including hours worked, */
/*overtime and wage using function. */
/*This version does not use file pointers. */
#include <stdio.h>
/* constants */
#define SIZE 5
#define OVERTIME_RATE 1.5f
#define STD_WORK_WEEK 40.0f
/* function prototypes */
float getHours (long clockNumber);
void printData (long int clockNumber[], float wageRate[], float hours[],
float overtime[], float gross[], int size);
float overtimeCalc (float hours);
float grossWage (float hours, float wageRate, float overtime);
int main()
{
/* Variable Declarations */
long int clockNumber[SIZE] = {98401,526488,765349,34645,127615}; /* ID */
float gross[SIZE]; /* gross pay */
float hours[SIZE]; /* hours worked in a given week */
int i; /* loop and array index */
float overtime[SIZE]; /* overtime hours */
float wageRate[SIZE] = {10.60,9.75,10.50,12.25,8.35}; /* hourly wage rate */
for (i = 0; i < SIZE; i++)
{
/* Function call to get input from user. */
hours[i] = getHours (clockNumber[i]);
/* Function call to calculate overtime */
overtime[i] = overtimeCalc (hours[i]);
printf("\nHours is %5.1f, wage is %5.2f, and overtime is %5.1f\n", hours[i], wageRate[i], overtime[i]);
/* Function call to calculate gross pay */
gross[i] = grossWage (hours[i], wageRate[i], overtime[i]);
printf("\nGross is %8.2f\n", gross
[i
]);
}
/* Print all the employees - call by reference */
printData (clockNumber, wageRate, hours,
overtime, gross, SIZE);
return (0);
}
//**************************************************************/
// Function: getHours
//
// Purpose: Obtains input from user, the number of hours worked
// per employee and stores the result in a 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
//
//**************************************************************/
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)
{
int count;
printf ("\n\n\tSusie Smith, C Programming, Fouth Homework Assignment\n"); printf ("\t----------------------------------------------------------\n"); printf ("\tClock# Wage Hours Overtime Gross\n"); printf ("\t----------------------------------------------------------\n"); for(count = 0; count < SIZE; count++)
{
printf ("\t%06li %10.2f %10.1f %10.1f %10.2f\n",clockNumber
[count
], wageRate
[count
], hours
[count
], overtime
[count
], gross
[count
]); }
}
//**************************************************************/
// Function: overtimeCalc
//
// Purpose: Calculates the amount of overtime hours an
// an employee has worked in the week.
//
// Parameters: hours - The amount of hours an emloyees has worked
//
// Returns: overtime - The amount of hours worked exceeded STD_WORK_WEEK
//
//**************************************************************/
float overtimeCalc (float hours)
{
float overtime; /* overtime hours */
/* check for overtime */
if (hours > STD_WORK_WEEK)
overtime = (hours - STD_WORK_WEEK);
else
overtime = 0;
return (overtime);
}
//**************************************************************/
// Function: grossWage
//
// Purpose: Calculates the gross wages of an employee
// for the week
//
// Parameters: hours - The amount of hours a the emloyee has worked
// overtime - the amount of overtime hours worked
// wageRate - hourly wage of the employee
//
// Returns: gross[] - gross pay for the week
//
//**************************************************************/
float grossWage (float hours, float wageRate, float overtime )
{
float otPay;
if (hours > STD_WORK_WEEK)
{
// Calculate overtime and gross pay for employee
otPay = ((OVERTIME_RATE * wageRate) * overtime);
otPay += (wageRate * STD_WORK_WEEK);
}
else
{
otPay = (wageRate * hours);
}
printf ("\n\notpay is %8.2f\n", otPay
);
return (otPay);
}