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