fork download
  1. //********************************************************
  2. //
  3. // Assignment 11 - Object Oriented Design
  4. //
  5. // Name: John Semenuk
  6. //
  7. // Class: C Programming, Spring 2026
  8. //
  9. // Date: April 25, 2026
  10. //
  11. // Description: An object oriented program design using
  12. // C++ that will process our existing set of employees.
  13. // It utilizes a class called Employee and generates an
  14. // array of objects that are used to store, calculate,
  15. // and print out a simple report of inputted and calculated
  16. // values.
  17. //
  18. //
  19. // Object Oriented Design (using C++)
  20. //
  21. //********************************************************
  22.  
  23. #include <stdio.h> // std::setprecision, std::setw
  24. #include <string.h> // std::cout, std::fixed
  25. #include <ctype.h> // string functions
  26.  
  27. // define constants
  28. #define STD_HOURS 40.0
  29. #define OT_RATE 1.5
  30. #define MA_TAX_RATE 0.05
  31. #define NH_TAX_RATE 0.0
  32. #define VT_TAX_RATE 0.06
  33. #define CA_TAX_RATE 0.07
  34. #define DEFAULT_TAX_RATE 0.08
  35. #define NAME_SIZE 20
  36. #define TAX_STATE_SIZE 3
  37. #define FED_TAX_RATE 0.25
  38. #define FIRST_NAME_SIZE 10
  39. #define LAST_NAME_SIZE 10
  40.  
  41. #define EMP_SIZE 5
  42.  
  43. // Employee structure
  44. struct Employee
  45. {
  46. char firstName[20];
  47. char lastName[20];
  48. char taxState[3];
  49. int clockNumber;
  50. float wageRate;
  51. float hours;
  52. float overTimeHrs;
  53. float grossPay;
  54. float stateTax;
  55. float fedTax;
  56. float netPay;
  57. };
  58.  
  59. // function prototypes
  60. float calcOverTimeHrs(float hours);
  61. float calcGrossPay(float wageRate, float hours, float overTimeHrs);
  62. float calcStateTax(float grossPay, char taxState[]);
  63. float calcFedTax(float grossPay);
  64. float calcNetPay(float grossPay, float stateTax, float fedTax);
  65. void printEmployee(struct Employee e);
  66.  
  67. // calculate overtime
  68. float calcOverTimeHrs(float hours)
  69. {
  70. if (hours > STD_HOURS)
  71. return hours - STD_HOURS;
  72. else
  73. return 0.0;
  74. }
  75.  
  76. // calculate gross pay
  77. float calcGrossPay(float wageRate, float hours, float overTimeHrs)
  78. {
  79. if (overTimeHrs > 0)
  80. {
  81. return (STD_HOURS * wageRate) +
  82. (overTimeHrs * wageRate * OT_RATE);
  83. }
  84. else
  85. {
  86. return wageRate * hours;
  87. }
  88. }
  89.  
  90. // calculate state tax
  91. float calcStateTax(float grossPay, char taxState[])
  92. {
  93. if (strcmp(taxState, "MA") == 0)
  94. return grossPay * MA_TAX_RATE;
  95. else if (strcmp(taxState, "VT") == 0)
  96. return grossPay * VT_TAX_RATE;
  97. else if (strcmp(taxState, "NH") == 0)
  98. return grossPay * NH_TAX_RATE;
  99. else if (strcmp(taxState, "CA") == 0)
  100. return grossPay * CA_TAX_RATE;
  101. else
  102. return grossPay * DEFAULT_TAX_RATE;
  103. }
  104.  
  105. // calculate federal tax
  106. float calcFedTax(float grossPay)
  107. {
  108. return grossPay * FED_TAX_RATE;
  109. }
  110.  
  111. // calculate net pay
  112. float calcNetPay(float grossPay, float stateTax, float fedTax)
  113. {
  114. return grossPay - stateTax - fedTax;
  115. }
  116.  
  117. // print employee report
  118. void printEmployee(struct Employee e)
  119. {
  120. printf("\n\n*** Entered Details are *** \n");
  121.  
  122. printf("\n First Name: %s", e.firstName);
  123. printf("\n Last Name: %s", e.lastName);
  124. printf("\n Tax State: %s", e.taxState);
  125. printf("\n Clock Number: %d", e.clockNumber);
  126. printf("\n Wage Rate: %.2f", e.wageRate);
  127. printf("\n Hours: %.2f", e.hours);
  128.  
  129. printf("\n\n *** Calculated Values are *** \n");
  130.  
  131. printf("\n Overtime Hours : %.2f", e.overTimeHrs);
  132. printf("\n Gross Pay : $%.2f", e.grossPay);
  133. printf("\n State Tax : $%.2f", e.stateTax);
  134. printf("\n Federal Tax : $%.2f", e.fedTax);
  135. printf("\n Net Pay : $%.2f", e.netPay);
  136.  
  137. printf("\n\n");
  138. }
  139.  
  140. // main function
  141. int main()
  142. {
  143. struct Employee e[EMP_SIZE];
  144. int i, j;
  145.  
  146. // process 5 employees
  147. for (i = 0; i < EMP_SIZE; i++)
  148. {
  149. printf("\n\n Enter Employee First Name: ");
  150. scanf("%19s", e[i].firstName);
  151.  
  152. printf("\n Enter Employee Last Name: ");
  153. scanf("%19s", e[i].lastName);
  154.  
  155. printf("\n Enter Employee Tax State: ");
  156. scanf("%2s", e[i].taxState);
  157.  
  158. // convert tax state to uppercase
  159. for (j = 0; e[i].taxState[j] != '\0'; j++)
  160. {
  161. e[i].taxState[j] = toupper(e[i].taxState[j]);
  162. }
  163.  
  164. printf("\n Enter Employee Clock Number: ");
  165. scanf("%d", &e[i].clockNumber);
  166.  
  167. printf("\n Enter Employee Hourly Wage Rate: ");
  168. scanf("%f", &e[i].wageRate);
  169.  
  170. printf("\n Enter Employee Hours Worked for the Week: ");
  171. scanf("%f", &e[i].hours);
  172.  
  173. // calculations
  174. e[i].overTimeHrs = calcOverTimeHrs(e[i].hours);
  175. e[i].grossPay = calcGrossPay(e[i].wageRate, e[i].hours, e[i].overTimeHrs);
  176. e[i].stateTax = calcStateTax(e[i].grossPay, e[i].taxState);
  177. e[i].fedTax = calcFedTax(e[i].grossPay);
  178. e[i].netPay = calcNetPay(e[i].grossPay, e[i].stateTax, e[i].fedTax);
  179.  
  180. // display report
  181. printEmployee(e[i]);
  182. }
  183.  
  184. return 0;
  185. }
Success #stdin #stdout 0s 5320KB
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