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. #define MA_TAX_RATE 0.05
  34. #define NH_TAX_RATE 0.0
  35. #define VT_TAX_RATE 0.06
  36. #define CA_TAX_RATE 0.07
  37. #define DEFAULT_TAX_RATE 0.08
  38. #define NAME_SIZE 20
  39. #define TAX_STATE_SIZE 3
  40. #define FED_TAX_RATE 0.25
  41. #define FIRST_NAME_SIZE 10
  42. #define LAST_NAME_SIZE 10
  43.  
  44. #define EMP_SIZE 5
  45.  
  46. using std::string;
  47.  
  48. // class Employee
  49. class Employee
  50. {
  51. private:
  52.  
  53. // private data available only to member functions
  54. // all data is initialized to support creating instances that
  55. // are not done via a full constructor with data to be used
  56.  
  57. string firstName = ""; // Employee First Name
  58. string lastName = ""; // Employee Last Name
  59. string taxState = ""; // Employee Tax State
  60. int clockNumber = 0; // Employee Clock Number
  61. float wageRate = 0.0; // Hourly Wage Rate
  62. float hours = 0.0; // Hours worked in a week
  63. float overTimeHrs = 0.0; // Overtime Hours worked
  64. float grossPay = 0.0; // Weekly Gross Pay
  65. float stateTax = 0.0; // State Tax
  66. float fedTax = 0.0; // Fed Tax
  67. float netPay = 0.0; // Net Pay
  68.  
  69. // private functions for call only by an Employee object
  70. // ... these are gernally more complex computations
  71. float calcOverTimeHrs();
  72. float calcGrossPay();
  73. float calcStateTax();
  74. float calcFedTax();
  75. float calcNetPay();
  76.  
  77. // Delcare "getter" function prototypes to retrieve private data
  78. // Note: The inline keyword is not required for the prototypes
  79. string getFirstName();
  80. string getLastName();
  81. string getTaxState();
  82. int getClockNumber();
  83. float getWageRate();
  84. float getHours();
  85. float getOverTimeHrs();
  86. float getGrossPay();
  87. float getStateTax();
  88. float getFedTax();
  89. float getNetPay();
  90.  
  91. public:
  92.  
  93. // public member functions that can be called
  94. // to access private data member items
  95.  
  96. // public no argument constructor with defaults
  97. // All Employee class data will be initialized to defaults
  98.  
  99. Employee() {} // destructor
  100.  
  101. Employee(string f, string l, string s,
  102. int c, float w, float h);
  103.  
  104. ~Employee() {}
  105. // print out Employee data to the console
  106. void printEmployee();
  107. };// End class declarations.
  108.  
  109. // ================= GETTERS =================
  110. inline string Employee::getFirstName() { return firstName; }
  111. inline string Employee::getLastName() { return lastName; }
  112. inline string Employee::getTaxState() { return taxState; }
  113. inline int Employee::getClockNumber() { return clockNumber; }
  114. inline float Employee::getWageRate() { return wageRate; }
  115. inline float Employee::getHours() { return hours; }
  116. inline float Employee::getOverTimeHrs() { return overTimeHrs; }
  117. inline float Employee::getGrossPay() { return grossPay; }
  118. inline float Employee::getStateTax() { return stateTax; }
  119. inline float Employee::getFedTax() { return fedTax; }
  120. inline float Employee::getNetPay() { return netPay; }
  121.  
  122. // private member function to calculate Overtime Hours
  123. float Employee::calcOverTimeHrs()
  124. {
  125. // Calculate the overtime hours for the week
  126. overTimeHrs = (hours > STD_HOURS) ? (hours - STD_HOURS) : 0;
  127. return overTimeHrs;
  128. }// the calculated overtime hours
  129.  
  130. float Employee::calcGrossPay()
  131. {
  132. if (overTimeHrs > 0)
  133. grossPay = (STD_HOURS * wageRate) + (overTimeHrs * wageRate * OT_RATE);
  134. else
  135. grossPay = hours * wageRate;
  136.  
  137. return grossPay;
  138. }
  139.  
  140. float Employee::calcStateTax()
  141. {
  142. float rate;
  143.  
  144. if (taxState == "MA") rate = MA_TAX_RATE;
  145. else if (taxState == "VT") rate = VT_TAX_RATE;
  146. else if (taxState == "NH") rate = NH_TAX_RATE;
  147. else if (taxState == "CA") rate = CA_TAX_RATE;
  148. else rate = DEFAULT_TAX_RATE;
  149.  
  150. stateTax = grossPay * rate;
  151. return stateTax;
  152. }
  153.  
  154. float Employee::calcFedTax()
  155. {
  156. fedTax = grossPay * FED_TAX_RATE;
  157. return fedTax;
  158. }
  159.  
  160. float Employee::calcNetPay()
  161. {
  162. netPay = grossPay - stateTax - fedTax;
  163. return netPay;
  164. }
  165.  
  166. // constructor with arguments
  167. Employee::Employee(string f, string l, string s,
  168. int c, float w, float h)
  169. {
  170. firstName = f;
  171. lastName = l;
  172.  
  173. if (islower(s[0])) s[0] = toupper(s[0]);
  174. if (islower(s[1])) s[1] = toupper(s[1]);
  175. taxState = s;
  176.  
  177. clockNumber = c;
  178. wageRate = w;
  179. hours = h;
  180.  
  181. overTimeHrs = calcOverTimeHrs();
  182. grossPay = calcGrossPay();
  183. stateTax = calcStateTax();
  184. fedTax = calcFedTax();
  185. netPay = calcNetPay();
  186. }
  187.  
  188. // a member function to print out the info in a given Employee object
  189. void Employee::printEmployee()
  190. {
  191. cout << "\n\n*** Entered Details are ***\n";
  192. cout << "First Name: " << getFirstName() << endl;
  193. cout << "Last Name: " << getLastName() << endl;
  194. cout << "Tax State: " << getTaxState() << endl;
  195. cout << "Clock Number: " << getClockNumber() << endl;
  196. cout << "Wage Rate: " << getWageRate() << endl;
  197. cout << "Hours: " << getHours() << endl;
  198.  
  199. cout << "\n*** Calculated Values are ***\n";
  200. cout << "Overtime Hours : " << getOverTimeHrs() << endl;
  201. cout << "Gross Pay : $" << getGrossPay() << endl;
  202. cout << "State Tax : $" << getStateTax() << endl;
  203. cout << "Federal Tax : $" << getFedTax() << endl;
  204. cout << "Net Pay : $" << getNetPay() << endl;
  205. }
  206.  
  207. // main function to start the processing
  208. int main()
  209. {
  210. cout << fixed << setprecision(2);
  211.  
  212. Employee e[EMP_SIZE];
  213.  
  214. for (int i = 0; i < EMP_SIZE; i++)
  215. {
  216. string f, l, s;
  217. int c;
  218. float w, h;
  219.  
  220. cout << "\n\n Enter Employee First Name: " << endl;
  221. cin >> f;
  222.  
  223. cout << " Enter Employee Last Name: " << endl;
  224. cin >> l;
  225.  
  226. cout << " Enter Employee Tax State: " << endl;
  227. cin >> s;
  228.  
  229. cout << " Enter Employee Clock Number: " << endl;
  230. cin >> c;
  231.  
  232. cout << " Enter Employee Hourly Wage Rate: " << endl;
  233. cin >> w;
  234.  
  235. cout << " Enter Employee Hours Worked for the Week: " << endl;
  236. cin >> h;
  237.  
  238. e[i] = Employee(f, l, s, c, w, h);
  239. e[i].printEmployee();
  240. }
  241.  
  242. return 0;
  243. }
Success #stdin #stdout 0s 5296KB
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