All pastes #243915 Raw Edit

Mine

public text v1 · immutable
·published 2006-11-09 01:15 UTC
rendered paste body
/*-----------------------------------------------------------------------*/
/*                                                                       */
/* HOMEWORK:    6 - Chapter 9                                            */
/*                                                                       */
/* Name:        Mike Chappell                                            */
/*                                                                       */
/* Class:       C Programming, Cybercourse, Fall 2006                    */
/*                                                                       */
/* Date:        10/20/06                                                 */
/*                                                                       */
/* Description: Program which determines gross Pay, calculates           */
/*              overtime and outputs a formated answer for               */
/*              multiple data sets using arrays and                      */
/*              functions and structures.                                */
/*                                                                       */
/*-----------------------------------------------------------------------*/

#include <stdio.h>

	/* Define Symbolic Constants */
#define EMP_NUM 5      /* Define number of employees as 5 */
#define OT_RATE 1.5    /* Define Overtime Rate as 1.5 */
#define FULL_TIME 40   /* Define Full Time as 40 */

	/* Define stuctures */

struct employee
{
int id_number;
float wage;
float hours;
float overtime;
float gross;
};

struct employee emp[EMP_NUM];
//struct employee pay = {10.60,9.75,10.50,12.25,8.35};
//struct employee id = {98401,526488,765349,34645,127615};

/*************************************************************************/
/*									 */
/*                      Function: prog_msg                  		 */
/*                                                                       */
/*  Purpose:     Displays program message                                */
/*                                                                       */
/*  Parameters:  nothing						 */
/*                                                                       */
/*  Returns:     nothing						 */
/*									 */
/*************************************************************************/

void prog_msg (void)
{
	printf("This program will calculate employee wages.\n\n");

	return;
}

/*************************************************************************/
/*									 */
/*                      Function: collect_hours                  	 */
/*                                                                       */
/*  Purpose:     Obtains input from user, the number of hours            */
/*               worked for each employee and stores the result          */
/*               in an array that is passed back to the calling          */
/*               program by reference.                                   */
/*                                                                       */
/*  Parameters:  id_number - Array of employee clock numbers             */
/*               hours    - Array of hours worked by employee            */
/*                                                                       */
/*  Returns:     Nothing, since 'id_number' & 'hours' arrays are         */
/*               passed by reference.                                    */
/*									 */
/*************************************************************************/

void collect_hours (struct employee id[])
{
    int index;   /* variable used as a loop counter */

    for (index = 0; index < EMP_NUM; ++index)
    {
		printf ("Enter the number of hours worked by employee # %06i:  ", id[index].id_number);
		scanf ("%f", &id[index].hours);
    }
     printf("\n");

	 return;
}

/*************************************************************************/
/*									 */
/*                      Function: calc_ot_hours                          */
/*                                                                       */
/*  Purpose:    Calculates the number of overtime hours given the number */
/*              of hours worked. Overtime hours are the number of hours  */
/*              worked after 40 hrs.                                     */
/*                                                                       */
/*  Parameters: hours   - Number of hours worked.                        */
/*                                                                       */
/*  Returns:    The number of overtime hours.                            */
/*									 */
/*************************************************************************/

void calc_ot_hours (struct employee emp[])
{
	int index;	/* variable used as a loop counter */

	for (index = 0; index < EMP_NUM; ++index)
    {
	if (emp[index].hours > FULL_TIME)
	{
	   emp[index].overtime = emp[index].hours - FULL_TIME;
	}
	else
	{
	   emp[index].overtime = 0;

    }
}
}

/*************************************************************************/
/*									 */
/*                      Function: calc_gross_pay                         */
/*                                                                       */
/*  Purpose:    Calculates gross pay including overtime given the number */
/*              of hours an employee works and wage rate.                */
/*                                                                       */
/*  Parameters: hours   - Array of Number of hours worked by employees   */
/*              wage    - Array of Hourly rates of employees.            */
/*              OT_Wage - Array of gross pay amounts for employees.      */
/*                                                                       */
/*  Returns:    Nothing since the gross_pay array is passed by reference */
/*																		 */
/*************************************************************************/

void calc_gross_pay(struct employee emp[])
{
	int index;   /*variable used as a loop counter*/
	calc_ot_hours (emp[index].hours, emp[index].overtime);
    for (index = 0; index < EMP_NUM; ++index)
	{
       if (emp[index].overtime >0)

	emp[index].gross = (emp[index].overtime * emp[index].wage * OT_RATE) + (FULL_TIME * emp[index].wage);

    else

	emp[index].gross = emp[index].wage * emp[index].hours;
    }
}

/*************************************************************************/
/*																		 */
/*                      Function: output                         		 */
/*                                                                       */
/*  Purpose:     Outputs in a table format the following:                */
/*                    - Employee Clock Number                            */
/*                    - wage Rate for Employee                           */
/*                    - Total hours worked by employee                   */
/*                    - Overtime hours                                   */
/*                    - gross Pay                                        */
/*                                                                       */
/*  Parameters:  id_number - Array of employee clock numbers             */
/*               hours     - Array of hours worked by employee           */
/*               gross     - Array of gross pay for employees            */
/*               overtime  - Array of OT hours                           */
/*               wage      - Array of employee wage rates                */
/*                                                                       */
/*  Returns:     Nothing.                                                */
/*																		 */
/*************************************************************************/

void output (struct employee emp[])
{

    int index;   /*variable used as a loop counter*/

    printf ("\n-------------EMPLOYEE WAGES------------\n");
	printf ("---------------------------------------\n");
    printf ("Clock#   Wage  Hours     OT     Gross\n");
    printf ("---------------------------------------\n");

    for (index = 0; index < EMP_NUM; ++index)
    {
	printf("%.06i %6.2f %6.1f %6.1f %9.2f\n", emp[index].id_number,emp[index].wage,emp[index].hours,emp[index].overtime,emp[index].gross);
    }
}


int main()
{

	/* Function call for Program Message */
   	prog_msg();

	/* Function Call to get input from user */
    collect_hours (); //emp[].id);

	/* Function Call to calculate overtime hours */
    calc_gross_pay (); //emp[].overtime, emp[].wage, emp[].hours, emp[].gross);

	/* Function Call to calculate gross pay */
    output (); //emp[].id_number, emp[].wage, emp[].hours, emp[].overtime, emp[].gross);

}b