fork download
  1. //********************************************************
  2. //
  3. // Assignment 11 - Object Oriented Design
  4. //
  5. // Name: Anthony Principe
  6. //
  7. // Class: C Programming, Fall 2025
  8. //
  9. // Date: 11/30/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. //**************************************************************
  45. // class Employee
  46. //
  47. // Contains all employee data items plus private calculation
  48. // functions that compute overtime, gross pay, taxes, and net pay.
  49. //**************************************************************
  50. class Employee
  51. {
  52. private:
  53.  
  54. // private data available only to member functions
  55.  
  56. string firstName; // Employee First Name
  57. string lastName; // Employee Last Name
  58. string taxState; // Employee Tax State
  59. int clockNumber; // Employee Clock Number
  60. float wageRate; // Hourly Wage Rate
  61. float hours; // Hours worked in a week
  62. float overTimeHrs; // Overtime Hours worked
  63. float grossPay; // Weekly Gross Pay
  64. float stateTax; // State Tax
  65. float fedTax; // Federal Tax
  66. float netPay; // Net Pay (take home amount)
  67.  
  68. // private member function to calculate Overtime Hours
  69. float calcOverTimeHrs ( )
  70. {
  71. // Determine overtime based on standard hours
  72. if (hours > STD_HOURS)
  73. overTimeHrs = hours - STD_HOURS;
  74. else
  75. overTimeHrs = 0;
  76.  
  77. return overTimeHrs;
  78. }
  79.  
  80. // private member function to calculate Gross Pay
  81. float calcGrossPay ( )
  82. {
  83. // Check for overtime and calculate appropriately
  84. if (overTimeHrs > 0)
  85. {
  86. grossPay = (STD_HOURS * wageRate)
  87. + (overTimeHrs * (wageRate * OT_RATE));
  88. }
  89. else
  90. {
  91. grossPay = wageRate * hours;
  92. }
  93.  
  94. return grossPay;
  95. }
  96.  
  97. // private member function to calculate State Tax
  98. float calcStateTax ()
  99. {
  100. float theStateTax = grossPay; // initialize with gross pay
  101.  
  102. // compute based on employee's state
  103. if (taxState.compare("MA") == 0)
  104. theStateTax *= MA_TAX_RATE;
  105. else if (taxState.compare("VT") == 0)
  106. theStateTax *= VT_TAX_RATE;
  107. else if (taxState.compare("NH") == 0)
  108. theStateTax *= NH_TAX_RATE;
  109. else if (taxState.compare("CA") == 0)
  110. theStateTax *= CA_TAX_RATE;
  111. else
  112. theStateTax *= DEFAULT_TAX_RATE; // for all other states
  113.  
  114. return theStateTax;
  115. }
  116.  
  117. // private member function to calculate Federal Tax
  118. float calcFedTax ()
  119. {
  120. float theFedTax;
  121.  
  122. // federal tax applies uniformly
  123. theFedTax = grossPay * FED_TAX_RATE;
  124.  
  125. return theFedTax;
  126. }
  127.  
  128. // private member function to calculate Net Pay
  129. float calcNetPay ()
  130. {
  131. float theTotalTaxes; // combined tax burden
  132. float theNetPay; // resulting take-home pay
  133.  
  134. theTotalTaxes = stateTax + fedTax;
  135. theNetPay = grossPay - theTotalTaxes;
  136.  
  137. return theNetPay;
  138. }
  139.  
  140. public:
  141.  
  142. // public no argument constructor with defaults
  143. Employee() {
  144. firstName = "";
  145. lastName = "";
  146. taxState = "";
  147. clockNumber = 0;
  148. wageRate = 0;
  149. hours = 0;
  150. overTimeHrs = 0;
  151. grossPay = 0;
  152. stateTax = 0;
  153. fedTax = 0;
  154. netPay = 0;
  155. }
  156.  
  157. // public constructor with arguments passed to it
  158. Employee (string myFirstName, string myLastName, string myTaxState,
  159. int myClockNumber, float myWageRate, float myHours);
  160.  
  161. ~Employee(); // destructor
  162.  
  163. // public getter function prototypes
  164. string getFirstName();
  165. string getLastName();
  166. string getTaxState();
  167. int getClockNumber();
  168. float getWageRate();
  169. float getHours();
  170. float getOverTimeHrs();
  171. float getGrossPay();
  172.  
  173. // newly added getter functions
  174. float getStateTax();
  175. float getFedTax();
  176. float getNetPay();
  177.  
  178. // member function to print an Employee object
  179. void printEmployee(Employee e);
  180. }; // class Employee
  181.  
  182.  
  183. //**************************************************************
  184. // Constructor with arguments
  185. //**************************************************************
  186. Employee::Employee (string myFirstName, string myLastName, string myTaxState,
  187. int myClockNumber, float myWageRate, float myHours)
  188. {
  189. // Initialize and/or set all inputted member data items
  190. firstName = myFirstName;
  191. lastName = myLastName;
  192.  
  193. // Convert tax state to uppercase
  194. if (std::islower(myTaxState[0]))
  195. myTaxState[0] = std::toupper(myTaxState[0]);
  196. if (std::islower(myTaxState[1]))
  197. myTaxState[1] = std::toupper(myTaxState[1]);
  198.  
  199. taxState = myTaxState;
  200. clockNumber = myClockNumber;
  201. wageRate = myWageRate;
  202. hours = myHours;
  203.  
  204. // Perform calculations using private functions
  205. overTimeHrs = calcOverTimeHrs();
  206. grossPay = calcGrossPay();
  207. stateTax = calcStateTax();
  208. fedTax = calcFedTax();
  209. netPay = calcNetPay();
  210. }
  211.  
  212. // destructor
  213. Employee::~Employee()
  214. {
  215. // Nothing special for this assignment
  216. }
  217.  
  218.  
  219. //**************************************************************
  220. // Getter functions
  221. //**************************************************************
  222. string Employee::getFirstName() { return firstName; }
  223. string Employee::getLastName() { return lastName; }
  224. string Employee::getTaxState() { return taxState; }
  225. int Employee::getClockNumber() { return clockNumber; }
  226. float Employee::getWageRate() { return wageRate; }
  227. float Employee::getHours() { return hours; }
  228. float Employee::getOverTimeHrs(){ return overTimeHrs; }
  229. float Employee::getGrossPay() { return grossPay; }
  230.  
  231. // new getters
  232. float Employee::getStateTax() { return stateTax; }
  233. float Employee::getFedTax() { return fedTax; }
  234. float Employee::getNetPay() { return netPay; }
  235.  
  236.  
  237. //**************************************************************
  238. // Function: printEmployee
  239. //
  240. // Prints all input fields and all calculated values.
  241. //**************************************************************
  242. void Employee::printEmployee(Employee e) {
  243.  
  244. // Display the inputted values
  245. cout<<"\n\n *** Entered Details are *** \n";
  246. cout<<"\n First Name: " << e.getFirstName();
  247. cout<<"\n Last Name: " << e.getLastName();
  248. cout<<"\n Tax State: " << e.getTaxState();
  249. cout<<"\n Clock Number: " << e.getClockNumber();
  250. cout<<"\n Wage Rate: " << e.getWageRate();
  251. cout<<"\n Hours: " << e.getHours();
  252.  
  253. // Display the calculated values
  254. cout<<"\n\n *** Calculated Values are *** \n";
  255. cout<<"\n Overtime Hours : " << e.getOverTimeHrs();
  256. cout<<"\n Gross Pay : $" << e.getGrossPay();
  257. cout<<"\n State Tax : $" << e.getStateTax();
  258. cout<<"\n Federal Tax : $" << e.getFedTax();
  259. cout<<"\n Net Pay : $" << e.getNetPay();
  260.  
  261. cout << "\n";
  262. }
  263.  
  264.  
  265. //**************************************************************
  266. // main function to start the processing
  267. //**************************************************************
  268. int main ()
  269. {
  270. // Local variables to store input temporarily
  271. string myFirstName;
  272. string myLastName;
  273. string myTaxState;
  274. int myClockNumber;
  275. float myWageRate;
  276. float myHours;
  277.  
  278. cout << fixed << setprecision(2);
  279.  
  280. // Array of Employee objects
  281. Employee e[EMP_SIZE];
  282.  
  283. // Read and process employee information
  284. for (int i = 0; i < EMP_SIZE; ++i)
  285. {
  286. cout <<"\n\n Enter Employee First Name: ";
  287. cin >> myFirstName;
  288.  
  289. cout <<"\n Enter Employee Last Name: ";
  290. cin >> myLastName;
  291.  
  292. cout <<"\n Enter Employee Tax State: ";
  293. cin >> myTaxState;
  294.  
  295. cout <<"\n Enter Employee Clock Number: ";
  296. cin >> myClockNumber;
  297.  
  298. cout <<"\n Enter Employee Hourly Wage Rate: ";
  299. cin >> myWageRate;
  300.  
  301. cout <<"\n Enter Employee Hours Worked for the Week: ";
  302. cin >> myHours;
  303.  
  304. // Create object using constructor with arguments
  305. e[i] = {myFirstName, myLastName, myTaxState,
  306. myClockNumber, myWageRate, myHours};
  307.  
  308. // Print all details
  309. e[i].printEmployee(e[i]);
  310. }
  311.  
  312. return 0;
  313. }
  314.  
Success #stdin #stdout 0s 5316KB
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