Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 7.95 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*-------------------------------------------------------------*/
  2. /*                                                             */
  3. /* HOMEWORK:    Homework #5                                    */
  4. /*                                                             */
  5. /* Name:        Chris Murphy                                   */
  6. /*                                                             */
  7. /* Class:       C Programming                                  */
  8. /*                                                             */
  9. /* Date:        July 8th, 2010                                 */
  10. /*                                                             */
  11. /* Description: Utilize functions to streamline pay calculator */
  12. /*              program.                                       */
  13. /*-------------------------------------------------------------*/
  14.  
  15. #include <stdio.h>
  16. #define OT_coeff 1.5
  17. #define slavery 168.0
  18. #define std_hours 40.0
  19.  
  20. int main (void)
  21. {
  22.     /* PROTOTYPES */
  23.     float calcPay (float hours, float wage);
  24.     float getHoursWorked (int clock);
  25.     float overTime (float hours);
  26.     float overTimeDisplay (float hours);
  27.     void printPay (int clock, float wage, float hours, float OT, float gross);
  28.    
  29.     /* VARIABLES */
  30.     int clock[] = { 98401, 526488, 765349, 34645, 127615 };
  31.     float gross[5];
  32.     float hours[5];
  33.     int i;
  34.     float OT[5];
  35.     float wage[] = { 10.60, 9.75, 10.50, 12.25, 8.35 };
  36.    
  37.     for ( i = 0; i < 5; i++ )                 // The function will do a simple
  38.         hours[i]= getHoursWorked(clock[i]);   // repetitive task, and it will be
  39.                                               // up to the main program to loop.
  40.     for ( i = 0; i < 5; i++ )
  41.     {
  42.         gross[i] = calcPay(hours[i], wage[i]); /* Gross can calculate OT, but it */
  43.         OT[i] = overTimeDisplay(hours[i]);     /* can't display the raw number   */
  44.     }
  45.    
  46.     printf("--------------------------------------------\n");
  47.     printf("Clock#    Wage    Hours     OT      Gross   \n");
  48.     printf("--------------------------------------------\n");
  49.    
  50.     for ( i = 0; i < 5; i++ )
  51.         printPay(clock[i], wage[i], hours[i], OT[i], gross[i]);
  52.        
  53.     return 0;
  54. }
  55.  
  56. /**************************************************************************/
  57. /*                        Function getHoursWorked                         */
  58. /*                                                                        */
  59. /*  Purpose:     This function is called when the user is asked to        */
  60. /*               input the hours of an employee.                          */
  61. /*                                                                        */
  62. /*  Parameters:  hours - # of hours the employee worked                   */
  63. /*               clock - the clock number of the employee                 */
  64. /*                                                                        */
  65. /*  Returns:     hours worked for the employee.                           */
  66. /**************************************************************************/
  67. float getHoursWorked (int clock)
  68. {
  69.     float hours;
  70.    
  71.     printf("Please enter the hours worked for %i: ", clock);
  72.     scanf("%f", &hours);
  73.     printf("\n");
  74.  
  75.     return hours;
  76. }
  77.  
  78. /**************************************************************************/
  79. /*                        Function calcPay                                */
  80. /*                                                                        */
  81. /*  Purpose:     This function is called when the program needs to        */
  82. /*               calculate the base pay of the employee, and calls        */
  83. /*               the OT function if the hours worked are over 40.         */
  84. /*                                                                        */
  85. /*  Parameters:  hours - # of hours the employee worked                   */
  86. /*               clock - the clock number of the employee                 */
  87. /*                                                                        */
  88. /*  Returns:     gross pay for the employee.                              */
  89. /**************************************************************************/
  90. float calcPay (float hours, float wage)
  91. {  
  92.     float OT;
  93.     float gross;
  94.    
  95.     if ( hours > slavery || hours < 0 )
  96.     {
  97.         gross = 0;
  98.     }
  99.     else if ( hours - std_hours > 0 )
  100.     {
  101.         OT = overTime(hours);
  102.         gross = wage * ( std_hours + OT );
  103.     }
  104.     else
  105.         gross = wage * hours;
  106.    
  107.     return gross;
  108. }
  109.  
  110. /**************************************************************************/
  111. /*                        Function overTime                               */
  112. /*                                                                        */
  113. /*  Purpose:     This function is used if OT calculations are needed.     */
  114. /*                                                                        */
  115. /*  Parameters:  hours - # of hours the employee worked                   */
  116. /*               OT - the weighted value of the overtime work.            */
  117. /*                    this is done to make calculations in calcPay easier.*/
  118. /*                                                                        */
  119. /*  Returns:     overtime worked by the employee.                         */
  120. /**************************************************************************/
  121. float overTime (float hours)
  122. {
  123.     float OT;
  124.    
  125.     OT = ( hours - std_hours ) * OT_coeff;
  126.    
  127.     return OT;
  128. }
  129.  
  130. /**************************************************************************/
  131. /*                        Function overTimeDisplay                        */
  132. /*                                                                        */
  133. /*  Purpose:     This function is used directly by main to store          */
  134. /*               overtime hours.                                          */
  135. /*                                                                        */
  136. /*  Parameters:  hours - # of hours the employee worked                   */
  137. /*               OT - the absolute number of overtime hours worked        */
  138. /*                    for display in main                                 */              
  139. /*                                                                        */
  140. /*  Returns:     overtime to be displayed later.                          */
  141. /**************************************************************************/    
  142. float overTimeDisplay (float hours)
  143. {
  144.     float OT;
  145.    
  146.     OT = ( hours - std_hours);
  147.    
  148.     if ( OT < 0 )
  149.         OT = 0;
  150.    
  151.     return OT;
  152. }
  153.  
  154. /**************************************************************************/
  155. /*                        Function printPay                               */
  156. /*                                                                        */
  157. /*  Purpose:     This function is used directly by main to display        */
  158. /*               the final statistics for the employees.                  */
  159. /*                                                                        */
  160. /*  Parameters:  clock - clock # of the employee.                         */
  161. /*               wage - wages earned by the employee.                     */      
  162. /*               hours - # of hours the employee worked.                  */
  163. /*               OT - the absolute number of overtime hours worked        */
  164. /*                    for display in main.                                */
  165. /*               gross - the gross pay for the employee.                  */              
  166. /*                                                                        */
  167. /*  Returns:     nothing                                                  */
  168. /**************************************************************************/
  169. void printPay (int clock, float wage, float hours, float OT, float gross)
  170. {
  171.     printf("%06i   ", clock);
  172.     printf("%5.2f    ", wage);
  173.     printf("%5.1f  ", hours);
  174.     printf("%5.1f     ", OT);
  175.     printf("%5.2f\n", gross);
  176. }