fork download
  1. //********************************************************
  2. //
  3. // Assignment 11 - Object Oriented Design
  4. //
  5. // Name: Tim Ticknor
  6. //
  7. // Class: C Programming, Fall, 2024
  8. //
  9. // Date: 12/1/2024
  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. string firstName; // Employee First Name
  51. string lastName; // Employee Last Name
  52. string taxState; // Employee Tax State
  53. int clockNumber; // Employee Clock Number
  54. float wageRate; // Hourly Wage Rate
  55. float hours; // Hours worked in a week
  56. float overTimeHrs; // Overtime Hours worked
  57. float grossPay; // Weekly Gross Pay
  58. float stateTax; // State Tax
  59. float fedTax; // Fed Tax
  60. float netPay; // Net Pay
  61.  
  62. // private member function to calculate Overtime Hours
  63. float calcOverTimeHrs ( )
  64. {
  65. if (hours > STD_HOURS)
  66. overTimeHrs = hours - STD_HOURS; // ot hours
  67. else
  68. overTimeHrs = 0; // no ot hours
  69. return (overTimeHrs);
  70. }
  71.  
  72. // private member function to calculate Gross Pay
  73. float calcGrossPay ( )
  74. {
  75. if (overTimeHrs > 0)
  76. {
  77. grossPay = (STD_HOURS * wageRate) + (overTimeHrs * (wageRate * OT_RATE));
  78. }
  79. else
  80. {
  81. grossPay = wageRate * hours;
  82. }
  83. return (grossPay);
  84. }
  85.  
  86. // private member function to calculate State Tax
  87. float calcStateTax ()
  88. {
  89. float theStateTax = grossPay; // initialize to gross pay
  90. if (taxState.compare("MA") == 0)
  91. theStateTax *= MA_TAX_RATE;
  92. else if (taxState.compare("VT") == 0)
  93. theStateTax *= VT_TAX_RATE;
  94. else if (taxState.compare("NH") == 0)
  95. theStateTax *= NH_TAX_RATE;
  96. else if (taxState.compare("CA") == 0)
  97. theStateTax *= CA_TAX_RATE;
  98. else
  99. theStateTax *= DEFAULT_TAX_RATE; // any other state
  100. return (theStateTax);
  101. }
  102.  
  103. // private member function to calculate Federal Tax
  104. float calcFedTax ()
  105. {
  106. return (grossPay * FED_TAX_RATE);
  107. }
  108.  
  109. // private member function to calculate Net Pay
  110. float calcNetPay ()
  111. {
  112. return (grossPay - (stateTax + fedTax));
  113. }
  114.  
  115. public:
  116.  
  117. // public member functions that can be called
  118. Employee() {firstName=""; lastName=""; taxState=""; clockNumber=0; wageRate=0; hours=0;}
  119.  
  120. Employee (string myFirstName, string myLastName, string myTaxState,
  121. int myClockNumber, float myWageRate, float myHours);
  122.  
  123. ~Employee(); // destructor
  124.  
  125. // public getter function prototypes to retrieve private data
  126. string getFirstName() { return firstName; }
  127. string getLastName() { return lastName; }
  128. string getTaxState() { return taxState; }
  129. int getClockNumber() { return clockNumber; }
  130. float getWageRate() { return wageRate; }
  131. float getHours() { return hours; }
  132. float getOverTimeHrs() { return overTimeHrs; }
  133. float getGrossPay() { return grossPay; }
  134.  
  135. // getter functions for stateTax, fedTax, and netPay
  136. float getStateTax() { return stateTax; }
  137. float getFedTax() { return fedTax; }
  138. float getNetPay() { return netPay; }
  139.  
  140. // member function prototype to print an Employee object
  141. void printEmployee(Employee e); // passes an object
  142. };
  143.  
  144. // constructor with arguments
  145. Employee::Employee (string myFirstName, string myLastName, string myTaxState,
  146. int myClockNumber, float myWageRate, float myHours)
  147. {
  148. firstName = myFirstName; // input
  149. lastName = myLastName; // input
  150.  
  151. // Convert myTaxState to uppercase if entered in lowercase
  152. if (std::islower(myTaxState[0]))
  153. myTaxState[0] = std::toupper(myTaxState[0]);
  154. if (std::islower(myTaxState[1]))
  155. myTaxState[1] = std::toupper(myTaxState[1]);
  156.  
  157. taxState = myTaxState; // input
  158. clockNumber = myClockNumber; // input
  159. wageRate = myWageRate; // input
  160. hours = myHours; // input
  161. overTimeHrs = calcOverTimeHrs(); // calculated overtime hours
  162. grossPay = calcGrossPay(); // calculated gross pay
  163.  
  164. // set stateTax, fedTax, and netPay using respective functions
  165. stateTax = calcStateTax();
  166. fedTax = calcFedTax();
  167. netPay = calcNetPay();
  168. }
  169.  
  170. // Employee's destructor
  171. Employee::~Employee()
  172. {
  173. // nothing to print here, but could ...
  174. }
  175.  
  176. // member function to print out the info in a given Employee object
  177. void Employee::printEmployee(Employee e) {
  178. cout<<"\n\n *** Entered Details are *** \n";
  179. cout<<"\n First Name: "<< e.getFirstName();
  180. cout<<"\n Last Name: "<< e.getLastName();
  181. cout<<"\n Tax State: "<< e.getTaxState();
  182. cout <<"\n Clock Number: "<< e.getClockNumber();
  183. cout <<"\n Wage Rate: "<< e.getWageRate ();
  184. cout <<"\n Hours: "<< e.getHours ();
  185.  
  186. cout<<"\n\n *** Calculated Values are *** \n";
  187.  
  188. cout <<"\n Overtime Hours : " << e.getOverTimeHrs();
  189. cout <<"\n Gross Pay : $" << e.getGrossPay();
  190.  
  191. // print out state tax
  192. cout <<"\n State Tax : $" << e.getStateTax();
  193.  
  194. // print out federal tax
  195. cout <<"\n Federal Tax : $" << e.getFedTax();
  196.  
  197. // print out net pay
  198. cout <<"\n Net Pay : $" << e.getNetPay();
  199.  
  200. cout <<"\n";
  201. }
  202.  
  203. // main function to start the processing
  204. int main ()
  205. {
  206. string myFirstName, myLastName, myTaxState;
  207. int myClockNumber;
  208. float myWageRate, myHours;
  209.  
  210. cout << fixed << setprecision(2); // fix the number of decimal digits to 2
  211.  
  212. Employee e[EMP_SIZE];
  213.  
  214. for (int i = 0; i < EMP_SIZE; ++i)
  215. {
  216. cout <<"\n\n Enter Employee First Name: ";
  217. cin>>myFirstName ;
  218. cout <<"\n Enter Employee Last Name: ";
  219. cin>>myLastName ;
  220. cout <<"\n Enter Employee Tax State: ";
  221. cin>>myTaxState ;
  222. cout<<"\n Enter Employee Clock Number: ";
  223. cin>>myClockNumber;
  224. cout <<"\n Enter Employee Hourly Wage Rate: ";
  225. cin>>myWageRate;
  226. cout <<"\n Enter Employee Hours Worked for the Week: ";
  227. cin>>myHours;
  228.  
  229. e[i] = {myFirstName, myLastName, myTaxState, myClockNumber, myWageRate, myHours};
  230.  
  231. e[i].printEmployee(e[i]);
  232. }
  233.  
  234. return 0;
  235. }
Success #stdin #stdout 0.01s 5280KB
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