fork(1) download
  1. //********************************************************
  2. //
  3. // Assignment 10 - Linked Lists, Typedef, and Macros
  4. //
  5. // Name:Jacquelin Saint lucien
  6. //
  7. // Class: C Programming, Falls 2025
  8. //
  9. // Date: 11/22/2025
  10. //
  11. // Description: Program which determines overtime and
  12. // gross pay for a set of employees with outputs sent
  13. // to standard output (the screen).
  14. //
  15. // This assignment also adds the employee name, their tax state,
  16. // and calculates the state tax, federal tax, and net pay. It
  17. // also calculates totals, averages, minimum, and maximum values.
  18. //
  19. // Array and Structure references have all been replaced with
  20. // pointer references to speed up the processing of this code.
  21. // A linked list has been created and deployed to dynamically
  22. // allocate and process employees as needed.
  23. //
  24. // It will also take advantage of the C Preprocessor features,
  25. // in particular with using macros, and will replace all
  26. // struct type references in the code with a typedef alias
  27. // reference.
  28. //
  29. // Call by Reference design (using pointers)
  30. //
  31. //********************************************************
  32.  
  33.  
  34.  
  35.  
  36. #include <stdio.h>
  37. #include <string.h>
  38.  
  39. #define MAX_EMPLOYEES 10
  40.  
  41. // ----- MACROS -----
  42. #define CALC_GROSS(hours, rate) ((hours) * (rate))
  43.  
  44. // corrected macros for min and max
  45. #define UPDATE_MIN(current, new) if((new) < (current)) current = (new)
  46. #define UPDATE_MAX(current, new) if((new) > (current)) current = (new)
  47.  
  48. // new macro for federal tax (10% as assumed in the homework)
  49. #define FED_TAX(gross) ((gross) * 0.10f)
  50.  
  51.  
  52. // ----- TYPEDEFS -----
  53. typedef struct {
  54. float min;
  55. float max;
  56. } MIN_MAX;
  57.  
  58.  
  59. // ----- STRUCTURES -----
  60. typedef struct {
  61. char first[20];
  62. char last[20];
  63. char state[3];
  64. int clockNumber;
  65. float wageRate;
  66. float hours;
  67. float gross;
  68. float federal;
  69. float net;
  70. } Employee;
  71.  
  72. typedef struct {
  73. float totalHours;
  74. float totalWages;
  75. float totalGross;
  76. float totalFederal;
  77. float totalNet;
  78. } Totals;
  79.  
  80.  
  81. // ----- FUNCTION PROTOTYPES -----
  82. void readEmployee(Employee *e);
  83. void computePayroll(Employee *e);
  84. void updateTotals(Totals *t, Employee e);
  85. void updateMinMax(MIN_MAX *m, float value);
  86. void printEmployee(Employee e);
  87. void printTotals(Totals t, MIN_MAX minHours, MIN_MAX maxHours);
  88.  
  89.  
  90. // ====================================================================
  91. // MAIN
  92. // ====================================================================
  93.  
  94. int main() {
  95. Employee list[MAX_EMPLOYEES];
  96. Totals totals = {0,0,0,0,0};
  97. MIN_MAX hoursMinMax = {999999, -999999};
  98. MIN_MAX grossMinMax = {999999, -999999};
  99.  
  100. int count = 5; // assignment uses 5 employees
  101.  
  102. for(int i = 0; i < count; i++) {
  103. readEmployee(&list[i]);
  104. computePayroll(&list[i]);
  105. updateTotals(&totals, list[i]);
  106.  
  107. updateMinMax(&hoursMinMax, list[i].hours);
  108. updateMinMax(&grossMinMax, list[i].gross);
  109. }
  110.  
  111. printf("\n*** Pay Calculator ***\n\n");
  112. printf("Name State Clock# Wage Hours Gross FedTax Net\n");
  113.  
  114. for(int i = 0; i < count; i++)
  115. printEmployee(list[i]);
  116.  
  117. printTotals(totals, hoursMinMax, grossMinMax);
  118.  
  119. return 0;
  120. }
  121.  
  122.  
  123. // ====================================================================
  124. // FUNCTION SIGNATURES
  125. // ====================================================================
  126.  
  127. void readEmployee(Employee *e) {
  128. scanf("%s %s %s %d %f %f",
  129. e->first, e->last, e->state,
  130. &e->clockNumber, &e->wageRate, &e->hours);
  131. }
  132.  
  133. void computePayroll(Employee *e) {
  134. e->gross = CALC_GROSS(e->hours, e->wageRate);
  135. e->federal = FED_TAX(e->gross);
  136. e->net = e->gross - e->federal;
  137. }
  138.  
  139. void updateTotals(Totals *t, Employee e) {
  140. t->totalHours += e.hours;
  141. t->totalWages += e.wageRate;
  142. t->totalGross += e.gross;
  143. t->totalFederal+= e.federal;
  144. t->totalNet += e.net;
  145. }
  146.  
  147. void updateMinMax(MIN_MAX *m, float value) {
  148. UPDATE_MIN(m->min, value);
  149. UPDATE_MAX(m->max, value);
  150. }
  151.  
  152. void printEmployee(Employee e) {
  153. printf("%-10s %-10s %-3s %6d %7.2f %7.2f %8.2f %8.2f %8.2f\n",
  154. e.first, e.last, e.state, e.clockNumber,
  155. e.wageRate, e.hours, e.gross, e.federal, e.net);
  156. }
  157.  
  158. void printTotals(Totals t, MIN_MAX minHours, MIN_MAX maxHours) {
  159. printf("\nTotals:\n");
  160. printf("Hours: %.2f\n", t.totalHours);
  161. printf("Gross: %.2f\n", t.totalGross);
  162. printf("Federal: %.2f\n", t.totalFederal);
  163. printf("Net: %.2f\n\n", t.totalNet);
  164.  
  165. printf("Min Hours Worked: %.2f\n", minHours.min);
  166. printf("Max Hours Worked: %.2f\n", maxHours.max);
  167. }
  168.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
*** Pay Calculator ***

Name            State Clock#   Wage  Hours   Gross   FedTax   Net
H U]�                �       0    0.00    0.00     0.00     0.00     0.00
                      \O:      0    0.00    -nan     -nan     -nan     -nan
��S]�     �                  0 950854219726848000.00    0.00     0.00     0.00     0.00
                      �  26577600    0.00    0.00     0.00     0.00     0.00
                              0    0.00    0.00     0.00     0.00     0.00

Totals:
Hours: -nan
Gross: -nan
Federal: -nan
Net: -nan

Min Hours Worked: 0.00
Max Hours Worked: 0.00