fork download
  1. //********************************************************
  2. //
  3. // Assignment 11 - Object Oriented Design
  4. //
  5. // Name: <Kyle Merrihew>
  6. //
  7. // Class: C Programming, <Spring 2025>
  8. //
  9. // Date: <April 25,2025>
  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.  
  27. // define constants
  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. #define FIRST_NAME_SIZE 10
  38. #define LAST_NAME_SIZE 10
  39.  
  40. using namespace std;
  41.  
  42. // class Employee
  43. class Employee
  44. {
  45. private:
  46. // private data available only to member functions
  47. string firstName; // Employee First Name
  48. string lastName; // Employee Last Name
  49. string taxState; // Employee Tax State
  50. int clockNumber; // Employee Clock Number
  51. float wageRate; // Hourly Wage Rate
  52. float hours; // Hours worked in a week
  53. float overTimeHrs; // Overtime Hours worked
  54. float grossPay; // Weekly Gross Pay
  55. float stateTax; // State Tax
  56. float fedTax; // Fed Tax
  57. float netPay; // Net Pay
  58.  
  59. // private member function to calculate Overtime Hours
  60. float calcOverTimeHrs ( )
  61. {
  62. if (hours > STD_HOURS)
  63. overTimeHrs = hours - STD_HOURS; // ot hours
  64. else
  65. overTimeHrs = 0; // no ot hours
  66. return (overTimeHrs);
  67. }
  68.  
  69. // private member function to calculate Gross Pay
  70. float calcGrossPay ( )
  71. {
  72. if (overTimeHrs > 0)
  73. {
  74. grossPay = (STD_HOURS * wageRate) + (overTimeHrs * (wageRate * OT_RATE)); // ot pay
  75. }
  76. else
  77. {
  78. grossPay = wageRate * hours; // normal pay
  79. }
  80. return (grossPay);
  81. }
  82.  
  83. // private member function to calculate State Tax
  84. float calcStateTax ()
  85. {
  86. float theStateTax = grossPay; // initialize to gross pay
  87.  
  88. if (taxState.compare("MA") == 0)
  89. theStateTax *= MA_TAX_RATE;
  90. else if (taxState.compare("VT") == 0)
  91. theStateTax *= VT_TAX_RATE;
  92. else if (taxState.compare("NH") == 0)
  93. theStateTax *= NH_TAX_RATE;
  94. else if (taxState.compare("CA") == 0)
  95. theStateTax *= CA_TAX_RATE;
  96. else
  97. theStateTax *= DEFAULT_TAX_RATE; // any other state
  98.  
  99. return (theStateTax);
  100. }
  101.  
  102. // private member function to calculate Federal Tax
  103. float calcFedTax ()
  104. {
  105. return grossPay * FED_TAX_RATE;
  106. }
  107.  
  108. // private member function to calculate Net Pay
  109. float calcNetPay ()
  110. {
  111. return grossPay - (stateTax + fedTax);
  112. }
  113.  
  114. public:
  115. Employee() {firstName=""; lastName=""; taxState="";
  116. clockNumber=0; wageRate=0; hours=0;}
  117.  
  118. Employee (string myFirstName, string myLastName, string myTaxState,
  119. int myClockNumber, float myWageRate, float myHours)
  120. {
  121. firstName = myFirstName;
  122. lastName = myLastName;
  123.  
  124. // Convert taxState to uppercase
  125. if (std::islower(myTaxState[0])) myTaxState[0] = std::toupper(myTaxState[0]);
  126. if (std::islower(myTaxState[1])) myTaxState[1] = std::toupper(myTaxState[1]);
  127.  
  128. taxState = myTaxState;
  129. clockNumber = myClockNumber;
  130. wageRate = myWageRate;
  131. hours = myHours;
  132. overTimeHrs = calcOverTimeHrs();
  133. grossPay = calcGrossPay();
  134. stateTax = calcStateTax();
  135. fedTax = calcFedTax();
  136. netPay = calcNetPay();
  137. }
  138.  
  139. // Getter functions
  140. string getFirstName() { return firstName; }
  141. string getLastName() { return lastName; }
  142. string getTaxState() { return taxState; }
  143. int getClockNumber() { return clockNumber; }
  144. float getWageRate() { return wageRate; }
  145. float getHours() { return hours; }
  146. float getOverTimeHrs() { return overTimeHrs; }
  147. float getGrossPay() { return grossPay; }
  148. float getStateTax() { return stateTax; }
  149. float getFedTax() { return fedTax; }
  150. float getNetPay() { return netPay; }
  151.  
  152. // Function to display entered details
  153. void printEnteredDetails()
  154. {
  155. cout << "*** Entered Details are ***" << endl;
  156. cout << endl;
  157. cout << "First Name: " << firstName << endl;
  158. cout << "Last Name: " << lastName << endl;
  159. cout << "Tax State: " << taxState << endl;
  160. cout << "Clock Number: " << clockNumber << endl;
  161. cout << "Wage Rate: " << fixed << setprecision(2) << wageRate << endl;
  162. cout << "Hours: " << fixed << setprecision(2) << hours << endl;
  163. }
  164.  
  165. // Function to display calculated values
  166. void printCalculatedValues()
  167. {
  168. cout << "*** Calculated Values are ***" << endl;
  169. cout << endl;
  170. cout << "Overtime Hours : " << fixed << setprecision(2) << overTimeHrs << endl;
  171. cout << "Gross Pay : $" << fixed << setprecision(2) << grossPay << endl;
  172. cout << "State Tax : $" << fixed << setprecision(2) << stateTax << endl;
  173. cout << "Federal Tax : $" << fixed << setprecision(2) << fedTax << endl;
  174. cout << "Net Pay : $" << fixed << setprecision(2) << netPay << endl;
  175. }
  176. };
  177.  
  178. int main()
  179. {
  180. string myFirstName, myLastName, myTaxState;
  181. int myClockNumber;
  182. float myWageRate, myHours;
  183.  
  184. Employee e[EMP_SIZE];
  185.  
  186. for (int i = 0; i < EMP_SIZE; ++i)
  187. {
  188. cout << "\nEnter Employee First Name: ";
  189. cin >> myFirstName;
  190. cout << "Enter Employee Last Name: ";
  191. cin >> myLastName;
  192. cout << "Enter Employee Tax State: ";
  193. cin >> myTaxState;
  194. cout << "Enter Employee Clock Number: ";
  195. cin >> myClockNumber;
  196. cout << "Enter Employee Hourly Wage Rate: ";
  197. cin >> myWageRate;
  198. cout << "Enter Employee Hours Worked for the Week: ";
  199. cin >> myHours;
  200.  
  201. // Create employee object
  202. e[i] = Employee(myFirstName, myLastName, myTaxState, myClockNumber, myWageRate, myHours);
  203.  
  204. // Print entered details and calculated values
  205. e[i].printEnteredDetails();
  206. e[i].printCalculatedValues();
  207. }
  208.  
  209. return 0;
  210. }
Success #stdin #stdout 0.01s 5292KB
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