//*******************************************************
//
// Homework: Assignment 4 (Chapter 7)
//
// Name: Brandon Shea
//
// Class: C Programming, Spring 2019
//
// Date: 2/20/19
//
// Description: Program which determines gross pay and outputs
// be sent to a designated file. It will add any overtime pay,
// if necessary, to the gross pay. This version uses arrays
// and does not use file pointers.
//
//********************************************************
#include <stdio.h>
// constants to be used
#define NUM_EMPL 5
#define OVERTIME_RATE 1.5f
#define STD_WORK_WEEK 40.0f
// function prototypes
float getHours (long clockNumber);
float getOvertimeHours(float hours);
float getOvertimePay(float overtime, float wage);
float getGross(float hours, float overtimePay, float wage);
void printData (long int clockNumber[], float wageRate[], float hours[],
float overtime[], float gross[], int size);
// main function
int main()
{
// Variable Declarations
long int clockNumber[NUM_EMPL] = {98401,526488,765349,34645,127615}; // employee clock number
float gross[NUM_EMPL]; // gross pay for a given week
float hours[NUM_EMPL]; // hours worked in a given week
int i; // loop and array index
float overtime[NUM_EMPL]; // number of overtime hours worked in a given week
float overtimePay[NUM_EMPL]; // overtime pay for a given week
float wage[NUM_EMPL] = {10.60,9.75,10.50,12.25,8.35}; // hourly wage
// process each employee
for (i = 0; i < NUM_EMPL; ++i)
{
// Function call to get hours worked input from user
hours[i] = getHours (clockNumber[i]);
// Function call to calculate overtime hours
overtime[i] = getOvertimeHours (hours[i]);
//function call to calculate overtime pay
overtimePay[i] = getOvertimePay (overtime[i], wage[i]);
// Function call to calculate gross pay
gross[i] = getGross (hours[i], overtimePay[i], wage[i]);
}
// Print the header info
printf ("\n\n\tTim Niesen, C Programming, Fourth Homework Assignment");
printf("\n\t-------------------------------------------------------\n");
printf("\tClock# Wage Hours OT Gross\n");
printf("\t-------------------------------------------------------\n");
// Print all the employees - call by reference
printData (clockNumber, wage, hours,
overtime, gross, NUM_EMPL);
return (0);
} // end main
//**************************************************************
// 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 the number of hours the employee worked for employee #: %06li: ", clockNumber);
scanf ("%f", &hoursWorked);
return (hoursWorked);
} // end function
//**************************************************************
// Function: getOvertimeHours
//
// Purpose: Calculates whether or not an employee worked
// overtime and how many hours of overtime they worked.
// Stores the result in a local variable that is passed back to
// the calling function.
//
// Parameters: hours - hours worked by employee in a given week
//
// Returns: otHours - overtime hours worked in a given week
//
//**************************************************************
float getOvertimeHours (float hours)
{
float otHours; // overtime hours worked in a given week
// if else statement to determine if overtime hours were worked
if (hours >= STD_WORK_WEEK)
{
otHours = hours - STD_WORK_WEEK;
}
else
{
otHours = 0;
}
return (otHours);
} // end function
//**************************************************************
// Function: getOvertimePay
//
// Purpose: Calculates how much an employee should be paid at
// the overtime rate. Stores the result in a local variable that
// is passed back to the calling function.
//
// Parameters:
//
// overtime - number of overtime hours worked in a given week
// wage - hourly wage
//
// Returns: otPay - overtime pay for a given week
//
//**************************************************************
float getOvertimePay (float overtime, float wage)
{
float otPay; // overtime pay for a given week
// if else statement to determine overtime pay, if applicable
if (overtime > 0)
{
otPay = overtime * (OVERTIME_RATE * wage);
}
else
{
otPay = 0;
}
return (otPay);
} // end function
//**************************************************************
// Function: getGross
//
// Purpose: Calculates what the gross pay for an employee will
// be for a given week. Stores the result in a local variable
// that is passed back to the calling function.
//
// Parameters:
//
// hours - hours worked in a given week
// overtimePay - overtime pay for week
// wage - hourly wage
//
// Returns: grossPay - gross pay for a given week
//
//**************************************************************
float getGross(float hours, float overtimePay, float wage)
{
float grossPay; // gross pay for a given week
// if else statement to determine how to calculate gross pay
if (overtimePay == 0)
{
grossPay = hours * wage;
}
else
{
grossPay = STD_WORK_WEEK * wage + overtimePay;
}
return (grossPay);
} // end function
//**************************************************************
// 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)
{
for (int i = 0; i < NUM_EMPL; i++)
{
// print employee information from arrays
printf("\t%06i %10.2f %10.1f %10.1f %10.2f\n", clockNumber[i], wageRate[i], hours[i], overtime[i], gross[i]);
}
return;
} // end function