#include <stdio.h>
//---------------- Constants ----------------//
#define SIZE 5 // number of employees
#define STD_HOURS 40.0 // standard work week
#define OT_RATE 1.5 // overtime pay rate
//---------------- Structure Definition ----------------//
struct employee {
long int clockNumber;
float wageRate;
float hours;
float overtimeHrs;
float grossPay;
};
//---------------- Function Prototypes ----------------//
float getHours(long int clockNumber);
float calcOvertime(float hours);
float calcGrossPay(float wageRate, float hours, float overtimeHrs);
void printHeader(void);
void printEmp(struct employee empList[], int size);
//**************************************************************
// ===== Function: main =====
// Purpose: Main driver function to process all employees.
// Parameters: None
// Returns: 0 on successful execution
//**************************************************************
int main(void)
{
struct employee empList[SIZE] = {
{98401, 10.60, 0, 0, 0},
{526488, 9.75, 0, 0, 0},
{765349, 10.50, 0, 0, 0},
{34645, 12.25, 0, 0, 0},
{127615, 8.35, 0, 0, 0}
};
printf("\n*** Pay Calculator ***\n\n");
// TODO: Process each employee (input, calculations)
for (int i = 0; i < SIZE; ++i)
{
empList[i].hours = getHours(empList[i].clockNumber);
empList[i].overtimeHrs = calcOvertime(empList[i].hours);
empList[i].grossPay = calcGrossPay(empList[i].wageRate, empList[i].hours, empList[i].overtimeHrs);
}
// TODO: Display results in table format
printHeader();
printEmp(empList, SIZE);
return 0;
}
//**************************************************************
// ===== Function: getHours =====
// Purpose: Prompts user for hours worked by each employee
// Parameters: clockNumber - (long int) employee ID
// Returns: (float) hours worked for the week
//**************************************************************
float getHours(long int clockNumber)
{
float hours;
// TODO: Read input for each employee
printf("Enter hours worked by emp #%06li: ", clockNumber
); return hours;
}
//**************************************************************
// ===== Function: calcOvertime =====
// Purpose: Calculates overtime hours if total hours exceed STD_HOURS
// Parameters: hours - (float) total hours worked
// Returns: (float) overtime hours worked, or 0 if none
//**************************************************************
float calcOvertime(float hours)
{
float overtime;
if (hours > STD_HOURS)
overtime = hours - STD_HOURS;
else
overtime = 0.0;
return overtime;
}
//**************************************************************
// ===== Function: calcGrossPay =====
// Purpose: Calculates gross pay, including normal and overtime pay
// Parameters:
// wageRate - (float) hourly wage
// hours - (float) total hours worked
// overtimeHrs - (float) overtime hours worked
// Returns: (float) total gross pay for the week
//**************************************************************
float calcGrossPay(float wageRate, float hours, float overtimeHrs)
{
// TODO: Apply overtime rate properly
if (hours > STD_HOURS)
return (STD_HOURS * wageRate) + (overtimeHrs * wageRate * OT_RATE);
else
return hours * wageRate;
}
//**************************************************************
// ===== Function: printHeader =====
// Purpose: Prints the header for the output table
// Parameters: None
// Returns: void
//**************************************************************
void printHeader(void)
{
// TODO: Format table neatly
printf("\n----------------------------------------------------------\n"); printf(" Clock# Wage Hours OT Gross\n"); printf("----------------------------------------------------------\n"); }
//**************************************************************
// ===== Function: printEmp =====
// Purpose: Displays all employee data in table format
// Parameters:
// empList - (struct employee[]) employee data
// size - (int) number of employees
// Returns: void
//**************************************************************
void printEmp(struct employee empList[], int size)
{
// TODO: Print all employee information clearly
for (int i = 0; i < size; ++i)
{
printf("%07li %7.2f %7.1f %7.1f %10.2f\n", empList[i].clockNumber,
empList[i].wageRate,
empList[i].hours,
empList[i].overtimeHrs,
empList[i].grossPay);
}
}