fork download
  1. //********************************************************
  2. //
  3. // Assignment 11 - Object Oriented Design
  4. //
  5. // Name: Jacquelin Saint Lucien
  6. //
  7. // Class: C Fall 2025
  8. //
  9. // Date: 11/29/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. using namespace std;
  27.  
  28. // define constants
  29. #define EMP_SIZE 5
  30. #define STD_HOURS 40.0
  31. #define OT_RATE 1.5
  32. #define MA_TAX_RATE 0.05
  33. #define NH_TAX_RATE 0.0
  34. #define VT_TAX_RATE 0.06
  35. #define CA_TAX_RATE 0.07
  36. #define DEFAULT_TAX_RATE 0.08
  37. #define NAME_SIZE 20
  38. #define TAX_STATE_SIZE 3
  39. #define FED_TAX_RATE 0.25
  40. #define FIRST_NAME_SIZE 10
  41. #define LAST_NAME_SIZE 10
  42.  
  43. // ----------------------------------------
  44. // Employee Class
  45. // ----------------------------------------
  46. class Employee {
  47. private:
  48. string firstName;
  49. string lastName;
  50. string state;
  51. int clockNum;
  52. double wage;
  53. double hours;
  54.  
  55. double overtimeHours;
  56. double grossPay;
  57. double stateTax;
  58. double federalTax;
  59. double netPay;
  60.  
  61. public:
  62.  
  63. void readInput() {
  64. cout << "Enter Employee First Name: ";
  65. cin >> firstName;
  66.  
  67. cout << "Enter Employee Last Name: ";
  68. cin >> lastName;
  69.  
  70. cout << "Enter Employee Tax State: ";
  71. cin >> state;
  72.  
  73. cout << "Enter Employee Clock Number: ";
  74. cin >> clockNum;
  75.  
  76. cout << "Enter Employee Hourly Wage Rate: ";
  77. cin >> wage;
  78.  
  79. cout << "Enter Employee Hours Worked for the Week: ";
  80. cin >> hours;
  81.  
  82. cout << endl;
  83. }
  84.  
  85. void calculate() {
  86. // overtime
  87. overtimeHours = (hours > 40) ? hours - 40 : 0;
  88.  
  89. // gross
  90. grossPay = (hours - overtimeHours) * wage +
  91. overtimeHours * wage * 1.5;
  92.  
  93. // state tax by state code
  94. if (state == "MA") stateTax = grossPay * 0.05;
  95. else if (state == "NH") stateTax = 0.00;
  96. else if (state == "VT") stateTax = grossPay * 0.06;
  97. else if (state == "NY") stateTax = grossPay * 0.08;
  98. else if (state == "CA") stateTax = grossPay * 0.07;
  99. else stateTax = 0;
  100.  
  101. // federal tax
  102. federalTax = grossPay * 0.25;
  103.  
  104. // net pay
  105. netPay = grossPay - stateTax - federalTax;
  106. }
  107.  
  108. void printResults() const {
  109. cout << " *** Entered Details are ***\n\n";
  110. cout << " First Name: " << firstName << endl;
  111. cout << " Last Name: " << lastName << endl;
  112. cout << " Tax State: " << state << endl;
  113. cout << " Clock Number: " << clockNum << endl;
  114. cout << fixed << setprecision(2);
  115. cout << " Wage Rate: " << wage << endl;
  116. cout << " Hours: " << hours << endl << endl;
  117.  
  118. cout << " *** Calculated Values are ***\n\n";
  119. cout << " Overtime Hours : " << overtimeHours << endl;
  120. cout << " Gross Pay : $" << grossPay << endl;
  121. cout << " State Tax : $" << stateTax << endl;
  122. cout << " Federal Tax : $" << federalTax << endl;
  123. cout << " Net Pay : $" << netPay << endl << endl;
  124. }
  125. };
  126.  
  127. // ----------------------------------------
  128. // Main Program
  129. // ----------------------------------------
  130. int main() {
  131. const int SIZE = 5;
  132. Employee emp[SIZE];
  133.  
  134. for (int i = 0; i < SIZE; i++) {
  135. emp[i].readInput();
  136. emp[i].calculate();
  137. emp[i].printResults();
  138. }
  139.  
  140. return 0;
  141. }
  142.  
  143.  
Success #stdin #stdout 0.01s 5296KB
stdin
Standard input is empty
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: 
 Last Name: 
 Tax State: 
 Clock Number: 0
 Wage Rate: 0.00
 Hours: 0.00

 *** Calculated Values are ***

 Overtime Hours : 0.00
 Gross Pay : $0.00
 State Tax : $0.00
 Federal Tax : $0.00
 Net Pay : $0.00

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: 
 Last Name: 
 Tax State: 
 Clock Number: 0
 Wage Rate: 0.00
 Hours: 0.00

 *** Calculated Values are ***

 Overtime Hours : 0.00
 Gross Pay : $0.00
 State Tax : $0.00
 Federal Tax : $0.00
 Net Pay : $0.00

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: 
 Last Name: 
 Tax State: 
 Clock Number: 0
 Wage Rate: 0.00
 Hours: 0.00

 *** Calculated Values are ***

 Overtime Hours : 0.00
 Gross Pay : $0.00
 State Tax : $0.00
 Federal Tax : $0.00
 Net Pay : $0.00

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: 
 Last Name: 
 Tax State: 
 Clock Number: -1131528416
 Wage Rate: 0.00
 Hours: 0.00

 *** Calculated Values are ***

 Overtime Hours : 0.00
 Gross Pay : $0.00
 State Tax : $0.00
 Federal Tax : $0.00
 Net Pay : $0.00

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: 
 Last Name: 
 Tax State: 
 Clock Number: 72703
 Wage Rate: 0.00
 Hours: 0.00

 *** Calculated Values are ***

 Overtime Hours : 0.00
 Gross Pay : $0.00
 State Tax : $0.00
 Federal Tax : $0.00
 Net Pay : $0.00