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 <iomanip> // std::setprecision, std::setw
  24. #include <iostream> // std::cout, std::fixed
  25. #include <string> // string functions
  26. #include <cctype>
  27.  
  28. using namespace std;
  29.  
  30. // define constants
  31. #define STD_HOURS 40.0
  32. #define OT_RATE 1.5
  33.  
  34. #define MA_TAX_RATE 0.05
  35. #define NH_TAX_RATE 0.0
  36. #define VT_TAX_RATE 0.06
  37. #define CA_TAX_RATE 0.07
  38. #define DEFAULT_TAX_RATE 0.08
  39.  
  40. #define FED_TAX_RATE 0.25
  41. #define EMP_SIZE 5
  42.  
  43. // class Employee
  44. class Employee
  45. {
  46. private:
  47.  
  48. // private data available only to member functions
  49. // all data is initialized to support creating instances that
  50. // are not done via a full constructor with data to be used
  51.  
  52. string firstName = ""; // Employee First Name
  53. string lastName = ""; // Employee Last Name
  54. string taxState = ""; // Employee Tax State
  55. int clockNumber = 0; // Employee Clock Number
  56. float wageRate = 0.0; // Hourly Wage Rate
  57. float hours = 0.0; // Hours worked in a week
  58. float overTimeHrs = 0.0; // Overtime Hours worked
  59. float grossPay = 0.0; // Weekly Gross Pay
  60. float stateTax = 0.0; // State Tax
  61. float fedTax = 0.0; // Fed Tax
  62. float netPay = 0.0; // Net Pay
  63.  
  64. // calculations
  65. float calcOverTimeHrs();
  66. float calcGrossPay();
  67. float calcStateTax();
  68. float calcFedTax();
  69. float calcNetPay();
  70.  
  71. // getters
  72. string getFirstName();
  73. string getLastName();
  74. string getTaxState();
  75. int getClockNumber();
  76. float getWageRate();
  77. float getHours();
  78. float getOverTimeHrs();
  79. float getGrossPay();
  80. float getStateTax();
  81. float getFedTax();
  82. float getNetPay();
  83.  
  84. public:
  85. Employee() {}
  86.  
  87. Employee(string f, string l, string s,
  88. int c, float w, float h);
  89.  
  90. ~Employee() {}
  91.  
  92. void printEmployee();
  93. };
  94.  
  95. // ================= GETTERS =================
  96. inline string Employee::getFirstName() { return firstName; }
  97. inline string Employee::getLastName() { return lastName; }
  98. inline string Employee::getTaxState() { return taxState; }
  99. inline int Employee::getClockNumber() { return clockNumber; }
  100. inline float Employee::getWageRate() { return wageRate; }
  101. inline float Employee::getHours() { return hours; }
  102. inline float Employee::getOverTimeHrs() { return overTimeHrs; }
  103. inline float Employee::getGrossPay() { return grossPay; }
  104. inline float Employee::getStateTax() { return stateTax; }
  105. inline float Employee::getFedTax() { return fedTax; }
  106. inline float Employee::getNetPay() { return netPay; }
  107.  
  108. // ================= CALCULATIONS =================
  109. float Employee::calcOverTimeHrs()
  110. {
  111. overTimeHrs = (hours > STD_HOURS) ? (hours - STD_HOURS) : 0;
  112. return overTimeHrs;
  113. }
  114.  
  115. float Employee::calcGrossPay()
  116. {
  117. if (overTimeHrs > 0)
  118. grossPay = (STD_HOURS * wageRate) + (overTimeHrs * wageRate * OT_RATE);
  119. else
  120. grossPay = hours * wageRate;
  121.  
  122. return grossPay;
  123. }
  124.  
  125. float Employee::calcStateTax()
  126. {
  127. float rate;
  128.  
  129. if (taxState == "MA") rate = MA_TAX_RATE;
  130. else if (taxState == "VT") rate = VT_TAX_RATE;
  131. else if (taxState == "NH") rate = NH_TAX_RATE;
  132. else if (taxState == "CA") rate = CA_TAX_RATE;
  133. else rate = DEFAULT_TAX_RATE;
  134.  
  135. stateTax = grossPay * rate;
  136. return stateTax;
  137. }
  138.  
  139. float Employee::calcFedTax()
  140. {
  141. fedTax = grossPay * FED_TAX_RATE;
  142. return fedTax;
  143. }
  144.  
  145. float Employee::calcNetPay()
  146. {
  147. netPay = grossPay - stateTax - fedTax;
  148. return netPay;
  149. }
  150.  
  151. // ================= CONSTRUCTOR =================
  152. Employee::Employee(string f, string l, string s,
  153. int c, float w, float h)
  154. {
  155. firstName = f;
  156. lastName = l;
  157.  
  158. if (islower(s[0])) s[0] = toupper(s[0]);
  159. if (islower(s[1])) s[1] = toupper(s[1]);
  160. taxState = s;
  161.  
  162. clockNumber = c;
  163. wageRate = w;
  164. hours = h;
  165.  
  166. overTimeHrs = calcOverTimeHrs();
  167. grossPay = calcGrossPay();
  168. stateTax = calcStateTax();
  169. fedTax = calcFedTax();
  170. netPay = calcNetPay();
  171. }
  172.  
  173. // ================= PRINT =================
  174. void Employee::printEmployee()
  175. {
  176. cout << "\n\n*** Entered Details are ***\n";
  177. cout << "First Name: " << getFirstName() << endl;
  178. cout << "Last Name: " << getLastName() << endl;
  179. cout << "Tax State: " << getTaxState() << endl;
  180. cout << "Clock Number: " << getClockNumber() << endl;
  181. cout << "Wage Rate: " << getWageRate() << endl;
  182. cout << "Hours: " << getHours() << endl;
  183.  
  184. cout << "\n*** Calculated Values are ***\n";
  185. cout << "Overtime Hours : " << getOverTimeHrs() << endl;
  186. cout << "Gross Pay : $" << getGrossPay() << endl;
  187. cout << "State Tax : $" << getStateTax() << endl;
  188. cout << "Federal Tax : $" << getFedTax() << endl;
  189. cout << "Net Pay : $" << getNetPay() << endl;
  190. }
  191.  
  192. // ================= MAIN =================
  193. // ================= MAIN =================
  194. int main()
  195. {
  196. cout << fixed << setprecision(2);
  197.  
  198. Employee e[EMP_SIZE];
  199.  
  200. for (int i = 0; i < EMP_SIZE; i++)
  201. {
  202. string f, l, s;
  203. int c;
  204. float w, h;
  205.  
  206. cout << "\n\nEnter Employee First Name: ";
  207. cin >> f;
  208.  
  209. cout << "Enter Employee Last Name: ";
  210. cin >> l;
  211.  
  212. cout << "Enter Employee Tax State: ";
  213. cin >> s;
  214.  
  215. cout << "Enter Employee Clock Number: ";
  216. cin >> c;
  217.  
  218. cout << "Enter Employee Hourly Wage Rate: ";
  219. cin >> w;
  220.  
  221. cout << "Enter Employee Hours Worked for the Week: ";
  222. cin >> h;
  223.  
  224. e[i] = Employee(f, l, s, c, w, h);
  225. e[i].printEmployee();
  226. }
  227.  
  228. return 0;
  229. }
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

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