fork(43) download
  1. /*--------------------------------------------------------------------------------
  2. **
  3. ** HOMEWORK: #5 Structures
  4. **
  5. ** Name: [Enter your Name]
  6. **
  7. ** Class: C Programming
  8. **
  9. ** Date: [enter the date]
  10. **
  11. ** Description: This program prompts the user for the number of hours
  12. ** worked for each employee. It then calculates gross pay
  13. ** including overtime and displays the results in table. Functions
  14. ** and structures are used.
  15. **-------------------------------------------------------------------------------*/
  16.  
  17. /*Define and Includes */
  18.  
  19. #include <stdio.h>
  20.  
  21. /* Define Constants */
  22. #define NUM_EMPL 5
  23. #define OVERTIME_RATE 1.5f
  24. #define STD_WORK_WEEK 40f
  25.  
  26. /* Define a global structure to pass employee data between functions */
  27. /* Note that the structure type is global, but you don't want a variable */
  28. /* of that type to be global. Best to declare a variable of that type */
  29. /* in a function like main or another function and pass as needed. */
  30. struct employee
  31. {
  32. long id_number;
  33. float wage;
  34. float hours;
  35. float overtime;
  36. float gross;
  37. };
  38.  
  39. /* define prototypes here for each function except main */
  40.  
  41. void Output_results_screen (struct employee [ ], int size);
  42.  
  43.  
  44. /*************************************************************************
  45. ** Function: Output_results_screen
  46. **
  47. ** Purpose: Outputs to screen in a table format the following
  48. ** information about an employee: Clock, Wage,
  49. ** Hours, Overtime, and Gross Pay.
  50. **
  51. ** Parameters: employeeData - an array of structures containing
  52. ** employee information
  53. ** size - number of employees to process
  54. **
  55. ** Returns: Nothing (void)
  56. **
  57. *************************************************************************/
  58.  
  59. void Output_results_screen ( struct employee employeeData[], int size )
  60. {
  61. int i; /* loop index */
  62.  
  63. /* printf information about each employee */
  64. for (i = 0; i < size ; ++i)
  65. {
  66. printf(" %06li %5.2f %4.1f %4.1f %8.2f \n",
  67. employeeData[i].id_number, employeeData[i].wage, employeeData[i].hours,
  68. employeeData[i].overtime, employeeData[i].gross);
  69. } /* for */
  70.  
  71. } /* Output_results_screen */
  72.  
  73.  
  74. int main ()
  75. {
  76. /* Variable Declaration and initialization */
  77. struct employee employeeData[NUM_EMPL] = {
  78. { 98401, 10.60 },
  79. { 526488, 9.75 },
  80. { 765349, 10.50 },
  81. { 34645, 12.25 },
  82. { 127615, 8.35 }
  83. };
  84.  
  85. /* Call various functions needed to reading, calculating, and printing as needed */
  86.  
  87. /* Function call to output results to the screen in table format. */
  88. Output_results_screen (employeeData, NUM_EMPL);
  89.  
  90. return(0); /* success */
  91.  
  92. } /* main */
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
     098401    10.60     0.0    0.0       0.00    
     526488     9.75     0.0    0.0       0.00    
     765349    10.50     0.0    0.0       0.00    
     034645    12.25     0.0    0.0       0.00    
     127615     8.35     0.0    0.0       0.00