//********************************************************
//
// Assignment 6 - Structures
//
// Name: Marin Haxhiaj
//
// Class: C Programming, Spring 2025
//
// Date: 03/08/2025
//
// Description: Program which determines overtime and
// gross pay for a set of employees with outputs sent
// to standard output (the screen).
//
// All functions are called by value
//
//********************************************************
#include <stdio.h>
// Define Constants
#define SIZE 5
#define STD_HOURS 40.0
#define OT_RATE 1.5
// Define a global structure to pass employee data between functions
struct employee
{
long int clockNumber;
float wageRate;
float hours;
float overtimeHrs;
float grossPay;
};
// Function prototypes
float getHours(long int clockNumber);
void printHeader(void);
void printEmp(long int clockNumber, float wageRate, float hours,
float overtimeHrs, float grossPay);
float calcOvertime(float hours);
float calcGrossPay(float wage, float hours, float overtimeHrs);
int main()
{
struct employee employeeData[SIZE] = {
{98401, 10.60},
{526488, 9.75},
{765349, 10.50},
{34645, 12.25},
{127615, 8.35}};
int i;
for (i = 0; i < SIZE; ++i)
{
employeeData[i].hours = getHours(employeeData[i].clockNumber);
employeeData[i].overtimeHrs = calcOvertime(employeeData[i].hours);
employeeData[i].grossPay = calcGrossPay(employeeData[i].wageRate,
employeeData[i].hours,
employeeData[i].overtimeHrs);
}
printHeader();
for (i = 0; i < SIZE; ++i)
{
printEmp(employeeData[i].clockNumber,
employeeData[i].wageRate,
employeeData[i].hours,
employeeData[i].overtimeHrs,
employeeData[i].grossPay);
}
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 unique employee ID
//
// Returns: hoursWorked - hours worked in a given week
//
//**************************************************************
float getHours(long int clockNumber)
{
float hoursWorked;
printf("\nEnter hours worked by emp # %06li: ", clockNumber
); scanf("%f", &hoursWorked
); return hoursWorked;
}
//**************************************************************
// Function: printHeader
//
// Purpose: Prints the initial table header information.
//
// Parameters: none
//
// Returns: void
//
//**************************************************************
void printHeader(void)
{
printf("\n\n*** Pay Calculator ***\n"); printf("\nClock# Wage Hours OT Gross\n"); printf("------------------------------------------------\n"); }
//*************************************************************
// Function: printEmp
//
// Purpose: Prints out all the information for an employee
// in a nice and orderly table format.
//
// Parameters:
//
// clockNumber - unique employee ID
// wageRate - hourly wage rate
// hours - Hours worked for the week
// overtimeHrs - overtime hours worked in a week
// grossPay - gross pay for the week
//
// Returns: void
//
//**************************************************************
void printEmp(long int clockNumber, float wageRate, float hours,
float overtimeHrs, float grossPay)
{
printf("\n %06li %5.2f %4.1f %4.1f %8.2f", clockNumber, wageRate, hours,
overtimeHrs, grossPay);
}
float calcOvertime(float hours)
{
if (hours > STD_HOURS)
{
return hours - STD_HOURS;
}
else
{
return 0.0;
}
}
float calcGrossPay(float wage, float hours, float overtimeHrs)
{
float regularPay = (hours - overtimeHrs) * wage;
float overtimePay = overtimeHrs * wage * OT_RATE;
return regularPay + overtimePay;
}