fork download
  1. /************************************************************************/
  2. /* */
  3. /* HOMEWORK: 8 */
  4. /* */
  5. /* Name: Matthew Tracy */
  6. /* */
  7. /* Class: C Programming, Cybercourse Spring 2026 */
  8. /* */
  9. /* Date: <04/03/2026> */
  10. /* */
  11. /* Description: Program which determines gross pay based on overtime */
  12. /* and outputs a formatted answer. Employee information */
  13. /* is stored in an array of structures and referenced */
  14. /* through the use of pointers. */
  15. /************************************************************************/
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19.  
  20. /* define all constants here */
  21. #define SIZE 5
  22.  
  23. /* type to hold employee information */
  24. struct employee
  25. {
  26. char name [20]; /* Employee first and last name */
  27. int id; /* unique employee identifier */
  28. float wage; /* hourly wage rate */
  29. float hours; /* hours worked in a given week */
  30. float overtime; /* hours worked after the standard work week */
  31. float gross; /* total gross pay, standard pay + overtime pay */
  32. };
  33.  
  34.  
  35. /* add function prototypes here if you wish */
  36.  
  37.  
  38. /* Remember to add function comment header block for each function */
  39. /* like shown below for printData, a hint for getHours is below. */
  40. float getHours ( int id )
  41. {
  42. float hours; /* hours worked for the employee */
  43.  
  44. /* prompt with id to read in a value for hours */
  45. return (hours);
  46. }
  47.  
  48.  
  49.  
  50. /************************************************************************/
  51. /* Function: printData */
  52. /* */
  53. /* Purpose: Outputs to screen in a table format the following: */
  54. /* - Employee First and Last Name */
  55. /* - Employee clock number */
  56. /* - Wage rate for an employee. */
  57. /* - Total hours worked by employee. */
  58. /* - Overtime Hours. */
  59. /* - Gross Pay. */
  60. /* */
  61. /* Parameters: emp_ptr - pointer to array of structures */
  62. /* size - number of employees to process */
  63. /* */
  64. /* Returns: Nothing, since emp_ptr is passed by reference */
  65. /************************************************************************/
  66.  
  67. void printData ( struct employee * emp_ptr, int size )
  68. {
  69. int n; /* counter used in for loop to keep track of iterations */
  70.  
  71. /* prints the output for all employees to the screen */
  72. for (n = 0; n < SIZE; n++)
  73. {
  74. printf ("%-20.20s %06i $%5.2f %4.1f %4.1f $%7.2f \n",
  75. emp_ptr->name,
  76. emp_ptr->id,
  77. emp_ptr->wage,
  78. emp_ptr->hours,
  79. emp_ptr->overtime,
  80. emp_ptr->gross);
  81.  
  82. ++emp_ptr; /* move to next employee */
  83. }
  84. printf ("\n");
  85. }
  86.  
  87.  
  88.  
  89. /************************************************************************/
  90. /* Function: Main */
  91. /************************************************************************/
  92.  
  93. int main()
  94. {
  95.  
  96. /* A structure array to hold information on employees */
  97. struct employee emp [SIZE] = { {"Connie Cobol", 98401, 10.60},
  98. {"Frank Fortran", 526488, 9.75},
  99. {"Mary Apl", 765349, 10.50},
  100. {"Jeff Ada", 34645, 12.25},
  101. {"Anton Pascal", 127615, 10.0}
  102. };
  103.  
  104. int i; /* loop and array index */
  105. struct employee * emp_ptr; /* pointer to an employee structure */
  106.  
  107. emp_ptr = emp; /* point to beginning of emp array */
  108.  
  109. /* Read in hours, and calculate overtime and gross */
  110. for (i=0; i < SIZE; ++i)
  111. {
  112.  
  113. /* Get user input for the hours worked for each employee */
  114. emp_ptr->hours = getHours ( emp_ptr->id );
  115.  
  116. /* Calculate overtime for each employee */
  117.  
  118. /* Calculate gross pay for each employee */
  119.  
  120. } /* end for */
  121.  
  122. /* Print column headers to the screen */
  123.  
  124. /* Print employee data to the screen */
  125. printData ( emp, SIZE );
  126.  
  127. return 0;
  128. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Connie Cobol         098401   $10.60      0.0       0.0    $   0.00 
Frank Fortran        526488   $ 9.75      0.0       0.0    $   0.00 
Mary Apl             765349   $10.50      0.0       0.0    $   0.00 
Jeff Ada             034645   $12.25      0.0       0.0    $   0.00 
Anton Pascal         127615   $10.00      0.0       0.0    $   0.00