fork download
  1. /********************************************************
  2.  *
  3.  * Assignment 11 - Object Oriented Design (C-Compatible Version)
  4.  *
  5.  * Name: John Semenuk
  6.  * Class: C Programming, Spring 2026
  7.  * Date: April 27, 2026
  8.  *
  9.  * Description:
  10.  * This version is rewritten in standard C so it will compile
  11.  * correctly as prog.c using gcc.
  12.  *
  13.  ********************************************************/
  14.  
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <ctype.h>
  18.  
  19. // constants
  20. #define STD_HOURS 40.0
  21. #define OT_RATE 1.5
  22. #define MA_TAX_RATE 0.05
  23. #define NH_TAX_RATE 0.0
  24. #define VT_TAX_RATE 0.06
  25. #define CA_TAX_RATE 0.07
  26. #define DEFAULT_TAX_RATE 0.08
  27. #define FED_TAX_RATE 0.25
  28. #define EMP_SIZE 5
  29.  
  30. // structure for Employee
  31. struct Employee
  32. {
  33. char firstName[20];
  34. char lastName[20];
  35. char taxState[3];
  36. int clockNumber;
  37. float wageRate;
  38. float hours;
  39. float overTimeHrs;
  40. float grossPay;
  41. float stateTax;
  42. float fedTax;
  43. float netPay;
  44. };
  45.  
  46. // function prototypes
  47. float calcOverTimeHrs(float hours);
  48. float calcGrossPay(float wageRate, float hours, float overTimeHrs);
  49. float calcStateTax(float grossPay, char taxState[]);
  50. float calcFedTax(float grossPay);
  51. float calcNetPay(float grossPay, float stateTax, float fedTax);
  52. void printEmployee(struct Employee e);
  53.  
  54. // overtime
  55. float calcOverTimeHrs(float hours)
  56. {
  57. if (hours > STD_HOURS)
  58. return hours - STD_HOURS;
  59. else
  60. return 0.0;
  61. }
  62.  
  63. // gross pay
  64. float calcGrossPay(float wageRate, float hours, float overTimeHrs)
  65. {
  66. if (overTimeHrs > 0)
  67. {
  68. return (STD_HOURS * wageRate) +
  69. (overTimeHrs * (wageRate * OT_RATE));
  70. }
  71. else
  72. {
  73. return wageRate * hours;
  74. }
  75. }
  76.  
  77. // state tax
  78. float calcStateTax(float grossPay, char taxState[])
  79. {
  80. if (strcmp(taxState, "MA") == 0)
  81. return grossPay * MA_TAX_RATE;
  82. else if (strcmp(taxState, "VT") == 0)
  83. return grossPay * VT_TAX_RATE;
  84. else if (strcmp(taxState, "NH") == 0)
  85. return grossPay * NH_TAX_RATE;
  86. else if (strcmp(taxState, "CA") == 0)
  87. return grossPay * CA_TAX_RATE;
  88. else
  89. return grossPay * DEFAULT_TAX_RATE;
  90. }
  91.  
  92. // federal tax
  93. float calcFedTax(float grossPay)
  94. {
  95. return grossPay * FED_TAX_RATE;
  96. }
  97.  
  98. // net pay
  99. float calcNetPay(float grossPay, float stateTax, float fedTax)
  100. {
  101. return grossPay - (stateTax + fedTax);
  102. }
  103.  
  104. // print employee
  105. void printEmployee(struct Employee e)
  106. {
  107. printf("\n\n*** Entered Details are *** \n");
  108.  
  109. printf("\n First Name: %s", e.firstName);
  110. printf("\n Last Name: %s", e.lastName);
  111. printf("\n Tax State: %s", e.taxState);
  112. printf("\n Clock Number: %d", e.clockNumber);
  113. printf("\n Wage Rate: %.2f", e.wageRate);
  114. printf("\n Hours: %.2f", e.hours);
  115.  
  116. printf("\n\n *** Calculated Values are *** \n");
  117.  
  118. printf("\n Overtime Hours : %.2f", e.overTimeHrs);
  119. printf("\n Gross Pay : $%.2f", e.grossPay);
  120. printf("\n State Tax : $%.2f", e.stateTax);
  121. printf("\n Federal Tax : $%.2f", e.fedTax);
  122. printf("\n Net Pay : $%.2f", e.netPay);
  123.  
  124. printf("\n\n");
  125. }
  126.  
  127. // main
  128. int main()
  129. {
  130. struct Employee e[EMP_SIZE];
  131. int i, j;
  132.  
  133. for (i = 0; i < EMP_SIZE; i++)
  134. {
  135. printf("\n\n Enter Employee First Name: ");
  136. scanf("%s", e[i].firstName);
  137.  
  138. printf("\n Enter Employee Last Name: ");
  139. scanf("%s", e[i].lastName);
  140.  
  141. printf("\n Enter Employee Tax State: ");
  142. scanf("%s", e[i].taxState);
  143.  
  144. // convert taxState to uppercase
  145. for (j = 0; e[i].taxState[j]; j++)
  146. {
  147. e[i].taxState[j] = toupper(e[i].taxState[j]);
  148. }
  149.  
  150. printf("\n Enter Employee Clock Number: ");
  151. scanf("%d", &e[i].clockNumber);
  152.  
  153. printf("\n Enter Employee Hourly Wage Rate: ");
  154. scanf("%f", &e[i].wageRate);
  155.  
  156. printf("\n Enter Employee Hours Worked for the Week: ");
  157. scanf("%f", &e[i].hours);
  158.  
  159. // calculations
  160. e[i].overTimeHrs = calcOverTimeHrs(e[i].hours);
  161. e[i].grossPay = calcGrossPay(e[i].wageRate, e[i].hours, e[i].overTimeHrs);
  162. e[i].stateTax = calcStateTax(e[i].grossPay, e[i].taxState);
  163. e[i].fedTax = calcFedTax(e[i].grossPay);
  164. e[i].netPay = calcNetPay(e[i].grossPay, e[i].stateTax, e[i].fedTax);
  165.  
  166. // output
  167. printEmployee(e[i]);
  168. }
  169.  
  170. return 0;
  171. }
  172.  
Success #stdin #stdout 0s 5308KB
stdin
Connie
Cobol
MA
98401
10.60
51.0
Mary
Apl
NH
526488
9.75
42.5
Frank
Fortran
VT
765349
10.50
37.0
Jeff
Ada
NY
34645
12.25
45
Anton
Pascal
CA
127615
8.35
40.0
stdout

 Enter Employee First Name: 
 Enter Employee Last Name: 
 Enter Employee Tax State: 
 Enter Employee Clock Number: 
 Enter Employee Hourly Wage Rate: 
 Enter Employee Hours Worked for the Week: 

*** Entered Details are *** 

 First Name: Connie
 Last Name: Cobol
 Tax State: MA
 Clock Number: 98401
 Wage Rate: 10.60
 Hours: 51.00

 *** Calculated Values are *** 

 Overtime Hours : 11.00
 Gross Pay : $598.90
 State Tax : $29.95
 Federal Tax : $149.73
 Net Pay : $419.23



 Enter Employee First Name: 
 Enter Employee Last Name: 
 Enter Employee Tax State: 
 Enter Employee Clock Number: 
 Enter Employee Hourly Wage Rate: 
 Enter Employee Hours Worked for the Week: 

*** Entered Details are *** 

 First Name: Mary
 Last Name: Apl
 Tax State: NH
 Clock Number: 526488
 Wage Rate: 9.75
 Hours: 42.50

 *** Calculated Values are *** 

 Overtime Hours : 2.50
 Gross Pay : $426.56
 State Tax : $0.00
 Federal Tax : $106.64
 Net Pay : $319.92



 Enter Employee First Name: 
 Enter Employee Last Name: 
 Enter Employee Tax State: 
 Enter Employee Clock Number: 
 Enter Employee Hourly Wage Rate: 
 Enter Employee Hours Worked for the Week: 

*** Entered Details are *** 

 First Name: Frank
 Last Name: Fortran
 Tax State: VT
 Clock Number: 765349
 Wage Rate: 10.50
 Hours: 37.00

 *** Calculated Values are *** 

 Overtime Hours : 0.00
 Gross Pay : $388.50
 State Tax : $23.31
 Federal Tax : $97.12
 Net Pay : $268.07



 Enter Employee First Name: 
 Enter Employee Last Name: 
 Enter Employee Tax State: 
 Enter Employee Clock Number: 
 Enter Employee Hourly Wage Rate: 
 Enter Employee Hours Worked for the Week: 

*** Entered Details are *** 

 First Name: Jeff
 Last Name: Ada
 Tax State: NY
 Clock Number: 34645
 Wage Rate: 12.25
 Hours: 45.00

 *** Calculated Values are *** 

 Overtime Hours : 5.00
 Gross Pay : $581.88
 State Tax : $46.55
 Federal Tax : $145.47
 Net Pay : $389.86



 Enter Employee First Name: 
 Enter Employee Last Name: 
 Enter Employee Tax State: 
 Enter Employee Clock Number: 
 Enter Employee Hourly Wage Rate: 
 Enter Employee Hours Worked for the Week: 

*** Entered Details are *** 

 First Name: Anton
 Last Name: Pascal
 Tax State: CA
 Clock Number: 127615
 Wage Rate: 8.35
 Hours: 40.00

 *** Calculated Values are *** 

 Overtime Hours : 0.00
 Gross Pay : $334.00
 State Tax : $23.38
 Federal Tax : $83.50
 Net Pay : $227.12