//********************************************************
//
// Assignment 6 - Structures
//
// Name: Morgan Card-Gimpelman
//
// Class: C Programming, Spring 2025
//
// Date: 3/9/25
//
// Description: Program which determines overtime and
// gross pay for a set of employees with outputs sent
// to standard output (the screen).
//
// Call by reference design
//
//********************************************************
// Define and Includes
#include <stdio.h>
// Define Constants
#define SIZE 5
#define STD_HOURS 40.0
#define OT_RATE 1.5
struct employee
{
long clockNumber; //Employee clock number
float wageRate; //Hourly wage rate
float hours; //Hours worked in a given week
float overtimeHrs; //Overtime hours
float grossPay; //Gross pay
};
//Function prototypes
void getHours (struct employee employeeData[], int theSize );
void printHeader (void);
void printEmp (struct employee emp [], int theSize);
void calcOT (struct employee employeeData[], int theSize);
void calcGross (struct employee employeeData[], int theSize);
int main ()
{
// Set up a local variable and initialize the clock and wages of my employees
struct employee employeeData [SIZE] = {
{ 98401, 10.60 },
{ 526488, 9.75 },
{ 765349, 10.50 },
{ 34645, 12.25 },
{ 127615, 8.35 }
};
// Call function needed to read hours
getHours (employeeData, SIZE);
// Call function to calculate ot hours
calcOT (employeeData, SIZE);
// Call function to calculate gross pay
calcGross (employeeData, SIZE);
// Print a table header
printHeader();
// Function call to output results to the screen in table format
printEmp (employeeData, SIZE);
return(0); // success
} // main
//**************************************************************
// Function: getHours
//
// Purpose: Obtains input from user, the number of hours worked
// per employee and stores the result in an array of structures
// that is passed back to the calling function by reference.
//
// Parameters:
//
// employeeData - an array of structures containing Employees
// theSize - number of employees to process
//
// Returns: Nothing (void)
//
//**************************************************************
void getHours (struct employee employeeData[], int theSize )
{
int i; // loop and array index
// read hours in for each employee
for (i = 0; i < theSize ; ++i)
{
printf("\nEnter hours worked by employee # %06li: ", employeeData[i].clockNumber);
scanf ("%f", &employeeData
[i
].
hours); } // for
} // getHours
//**************************************************************
// Function: printHeader
//
// Purpose: Prints the initial table header information.
//
// Parameters: none
//
// Returns: void
//
//**************************************************************
void printHeader (void)
{
printf ("\n\n*** Pay Calculator ***\n");
// print the table header
printf("\nClock# Wage Hours OT Gross\n"); printf("------------------------------------------------\n");
} // printHeader
// ********************************************************************
// Function: printEmp
//
// Purpose: Outputs to screen in a table format the following
// information about an employee: Clock, Wage,
// Hours, Overtime Hours, and Gross Pay.
//
// Parameters:
//
// employeeData - an array of structures containing Employees
// theSize - number of employees to process
//
// Returns: Nothing (void)
//
// *********************************************************************
void printEmp ( struct employee employeeData[], int theSize )
{
int i; // loop and array index
// print information about each employee
for (i = 0; i < theSize ; ++i)
{
printf("\n %06li %5.2f %4.1f %4.1f %8.2f", employeeData[i].clockNumber, employeeData[i].wageRate, employeeData[i].hours,
employeeData[i].overtimeHrs, employeeData[i].grossPay);
} /* for */
} // printEmp
// ********************************************************************
// Function: calcOT
//
// Purpose: Calculates the overtime hours for an employee
//
// Parameters:
//
// hours - hours worked for the week
//
// Returns: overtimeHrs - overtime hours worked in a week
//
// *********************************************************************
void calcOT (struct employee employeeData[], int theSize)
{
//declare local variables
int i; //loop and array index
//Update the overtime hours for each employee
for(i = 0; i < theSize ; ++i)
{
if (employeeData[i].hours >= STD_HOURS) //Hours over forty
{
employeeData[i].overtimeHrs = employeeData[i].hours - STD_HOURS; //Overtime hours calculation
}
else //Hours under forty
{
employeeData[i].overtimeHrs = 0;
}
}//for
}//calcOT
// ********************************************************************
// Function: calcGross
//
// Purpose: calculates the gross pay of an employee
//
// Parameters:
//
// hours - hours worked for the week
// wageRate - hourly wage rate
// overtimeHrs - overtime hours worked in a week
//
// Returns: grossPay - gross pay for an employee
//
// *********************************************************************
void calcGross (struct employee employeeData[], int theSize)
{
//declare local variables
int i; //loop and array index
float normalPay; //normal pay earned
float overtimePay; //overtime pay earned
//update the gross pay for each employee
for(i = 0; i < theSize ; ++i)
{
if (employeeData[i].hours >= STD_HOURS) //Hours over forty
{
normalPay = STD_HOURS * employeeData[i].wageRate; //Normal pay calculation
//Overtime pay calculation
overtimePay = employeeData[i].overtimeHrs * (employeeData[i].wageRate * OT_RATE);
employeeData[i].grossPay = normalPay + overtimePay; //Gross pay calculation over forty hours
}
else //Hours under forty
{
overtimePay = 0;
//Gross pay calculation under forty hours
employeeData[i].grossPay = employeeData[i].hours * employeeData[i].wageRate;
}
}//for
} //calcGross