fork download
  1. //********************************************************
  2. //
  3. // Assignment 11 - Object Oriented Design
  4. //
  5. // Name: MARTIN CLYTON MAYANJA
  6. //
  7. // Class: C Programming, SPRING,2026
  8. //
  9. // Date: 24APRIL2026
  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 <iomanip>
  24. #include <iostream>
  25. #include <string>
  26. #include <cctype>
  27.  
  28. #define EMP_SIZE 5
  29. #define STD_HOURS 40.0
  30. #define OT_RATE 1.5
  31. #define MA_TAX_RATE 0.05
  32. #define NH_TAX_RATE 0.0
  33. #define VT_TAX_RATE 0.06
  34. #define CA_TAX_RATE 0.07
  35. #define DEFAULT_TAX_RATE 0.08
  36. #define FED_TAX_RATE 0.25
  37.  
  38. using namespace std;
  39.  
  40. // class Employee
  41. class Employee
  42. {
  43. private:
  44. string firstName;
  45. string lastName;
  46. string taxState;
  47. int clockNumber;
  48. float wageRate;
  49. float hours;
  50. float overTimeHrs;
  51. float grossPay;
  52. float stateTax;
  53. float fedTax;
  54. float netPay;
  55.  
  56. float calcOverTimeHrs ()
  57. {
  58. if (hours > STD_HOURS)
  59. overTimeHrs = hours - STD_HOURS;
  60. else
  61. overTimeHrs = 0;
  62.  
  63. return overTimeHrs;
  64. }
  65.  
  66. float calcGrossPay ()
  67. {
  68. if (overTimeHrs > 0)
  69. grossPay = (STD_HOURS * wageRate) +
  70. (overTimeHrs * (wageRate * OT_RATE));
  71. else
  72. grossPay = wageRate * hours;
  73.  
  74. return grossPay;
  75. }
  76.  
  77. float calcStateTax ()
  78. {
  79. float theStateTax = grossPay;
  80.  
  81. if (taxState == "MA")
  82. theStateTax *= MA_TAX_RATE;
  83. else if (taxState == "VT")
  84. theStateTax *= VT_TAX_RATE;
  85. else if (taxState == "NH")
  86. theStateTax *= NH_TAX_RATE;
  87. else if (taxState == "CA")
  88. theStateTax *= CA_TAX_RATE;
  89. else
  90. theStateTax *= DEFAULT_TAX_RATE;
  91.  
  92. return theStateTax;
  93. }
  94.  
  95. float calcFedTax ()
  96. {
  97. return grossPay * FED_TAX_RATE;
  98. }
  99.  
  100. float calcNetPay ()
  101. {
  102. return grossPay - (stateTax + fedTax);
  103. }
  104.  
  105. public:
  106.  
  107. Employee()
  108. {
  109. firstName = "";
  110. lastName = "";
  111. taxState = "";
  112. clockNumber = 0;
  113. wageRate = 0;
  114. hours = 0;
  115. overTimeHrs = 0;
  116. grossPay = 0;
  117. stateTax = 0;
  118. fedTax = 0;
  119. netPay = 0;
  120. }
  121.  
  122. Employee (string myFirstName, string myLastName, string myTaxState,
  123. int myClockNumber, float myWageRate, float myHours);
  124.  
  125. ~Employee();
  126.  
  127. string getFirstName();
  128. string getLastName();
  129. string getTaxState();
  130. int getClockNumber();
  131. float getWageRate();
  132. float getHours();
  133. float getOverTimeHrs();
  134. float getGrossPay();
  135.  
  136. // TODO - Add public getter function prototype to retrieve stateTax
  137. float getStateTax();
  138.  
  139. // TODO - Add public getter function prototype to retrieve fedTax
  140. float getFedTax();
  141.  
  142. // TODO - Add public getter function prototype to retrieve netPay
  143. float getNetPay();
  144.  
  145. void printEmployee(Employee e);
  146. };
  147.  
  148. // constructor
  149. Employee::Employee (string myFirstName, string myLastName, string myTaxState,
  150. int myClockNumber, float myWageRate, float myHours)
  151. {
  152. firstName = myFirstName;
  153. lastName = myLastName;
  154.  
  155. if (islower(myTaxState[0]))
  156. myTaxState[0] = toupper(myTaxState[0]);
  157. if (islower(myTaxState[1]))
  158. myTaxState[1] = toupper(myTaxState[1]);
  159.  
  160. taxState = myTaxState;
  161. clockNumber = myClockNumber;
  162. wageRate = myWageRate;
  163. hours = myHours;
  164.  
  165. overTimeHrs = calcOverTimeHrs();
  166. grossPay = calcGrossPay();
  167.  
  168. // TODO - set stateTax as the return from calcStateTax member function
  169. stateTax = calcStateTax();
  170.  
  171. // TODO - set fedTax as the return from calcFedTax member function
  172. fedTax = calcFedTax();
  173.  
  174. // TODO - set netPay as the return from calcNetPay member function
  175. netPay = calcNetPay();
  176. }
  177.  
  178. Employee::~Employee() {}
  179.  
  180. string Employee::getFirstName() { return firstName; }
  181. string Employee::getLastName() { return lastName; }
  182. string Employee::getTaxState() { return taxState; }
  183. int Employee::getClockNumber() { return clockNumber; }
  184. float Employee::getWageRate() { return wageRate; }
  185. float Employee::getHours() { return hours; }
  186. float Employee::getOverTimeHrs() { return overTimeHrs; }
  187. float Employee::getGrossPay() { return grossPay; }
  188.  
  189. // TODO - Add a "getter" function that will retrieve the employee stateTax
  190. float Employee::getStateTax() { return stateTax; }
  191.  
  192. // TODO - Add a "getter" function that will retrieve the employee fedTax
  193. float Employee::getFedTax() { return fedTax; }
  194.  
  195. // TODO - Add a "getter" function that will retrieve the employee netPay
  196. float Employee::getNetPay() { return netPay; }
  197.  
  198. void Employee::printEmployee(Employee e)
  199. {
  200. cout << "\n\n *** Entered Details are *** \n";
  201. cout << "\n First Name: " << e.getFirstName();
  202. cout << "\n Last Name: " << e.getLastName();
  203. cout << "\n Tax State: " << e.getTaxState();
  204. cout << "\n Clock Number: " << e.getClockNumber();
  205. cout << "\n Wage Rate: " << e.getWageRate();
  206. cout << "\n Hours: " << e.getHours();
  207.  
  208. cout << "\n\n *** Calculated Values are *** \n";
  209. cout << "\n Overtime Hours : " << e.getOverTimeHrs();
  210. cout << "\n Gross Pay : $" << e.getGrossPay();
  211.  
  212. // TODO - Add cout statement with call to stateTax getter function
  213. cout << "\n State Tax : $" << e.getStateTax();
  214.  
  215. // TODO - Add cout statement with call to fedTax getter function
  216. cout << "\n Fed Tax : $" << e.getFedTax();
  217.  
  218. // TODO - Add cout statement with call to netPay getter function
  219. cout << "\n Net Pay : $" << e.getNetPay();
  220.  
  221. cout << "\n";
  222. }
  223.  
  224. int main ()
  225. {
  226. string myFirstName, myLastName, myTaxState;
  227. int myClockNumber;
  228. float myWageRate, myHours;
  229.  
  230. cout << fixed << setprecision(2);
  231.  
  232. Employee e[EMP_SIZE];
  233.  
  234. for (int i = 0; i < EMP_SIZE; ++i)
  235. {
  236. cin >> myFirstName >> myLastName >> myTaxState
  237. >> myClockNumber >> myWageRate >> myHours;
  238.  
  239. e[i] = Employee(myFirstName, myLastName, myTaxState,
  240. myClockNumber, myWageRate, myHours);
  241.  
  242. e[i].printEmployee(e[i]);
  243. }
  244.  
  245. return 0;
  246. } // main
  247.  
Success #stdin #stdout 0.01s 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

 *** 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
 Fed Tax : $149.73
 Net Pay : $419.23


 *** 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
 Fed Tax : $106.64
 Net Pay : $319.92


 *** 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
 Fed Tax : $97.12
 Net Pay : $268.07


 *** 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
 Fed Tax : $145.47
 Net Pay : $389.86


 *** 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
 Fed Tax : $83.50
 Net Pay : $227.12