fork download
  1. //********************************************************
  2. //
  3. // Assignment 11 - Object Oriented Design
  4. //
  5. // Name: <Esan Adams>
  6. //
  7. // Class: C Programming, <Fall 2024>
  8. //
  9. // Date: <November 25, 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.  
  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. // Calculate the overtime hours for the week
  67. if (hours > STD_HOURS)
  68. overTimeHrs = hours - STD_HOURS; // ot hours
  69. else
  70. overTimeHrs = 0; // no ot hours
  71.  
  72. // the calculated overtime hours
  73. return (overTimeHrs);
  74.  
  75. } // calcOverTimeHrs
  76.  
  77. // private member function to calculate Gross Pay
  78. float calcGrossPay ( )
  79. {
  80. // Process gross pay based on if there is overtime
  81. if (overTimeHrs > 0)
  82. {
  83. // overtime
  84. grossPay = (STD_HOURS * wageRate) // normal pay
  85. + (overTimeHrs * (wageRate * OT_RATE)); // ot pay
  86. }
  87. else // no overtime pay
  88. {
  89. grossPay = wageRate * hours; // normal pay
  90. }
  91.  
  92. // the calculated gross pay
  93. return (grossPay);
  94.  
  95. } // calcGrossPay
  96.  
  97. // private member function to calculate State Tax
  98. float calcStateTax ()
  99. {
  100.  
  101. float theStateTax; // calculated state tax
  102.  
  103. theStateTax = grossPay; // initialize to gross pay
  104.  
  105. // calculate state tax based on where employee resides
  106.  
  107. if (taxState.compare("MA") == 0)
  108. theStateTax *= MA_TAX_RATE;
  109. else if (taxState.compare("VT") == 0)
  110. theStateTax *= VT_TAX_RATE;
  111. else if (taxState.compare("NH") == 0)
  112. theStateTax *= NH_TAX_RATE;
  113. else if (taxState.compare("CA") == 0)
  114. theStateTax *= CA_TAX_RATE;
  115. else
  116. theStateTax *= DEFAULT_TAX_RATE; // any other state
  117.  
  118. // return the calculated state tax
  119. return (theStateTax);
  120.  
  121. } // calcStateTax
  122.  
  123. // private member function to calculate Federal Tax
  124. float calcFedTax ()
  125. {
  126.  
  127. float theFedTax; // The calculated Federal Tax
  128.  
  129. // Federal Tax is the same for all regardless of state
  130. theFedTax = grossPay * FED_TAX_RATE;
  131.  
  132. // return the calculated federal tax
  133. return (theFedTax);
  134.  
  135. } // calcFedTax
  136.  
  137. // private member function to calculate Net Pay
  138. float calcNetPay ()
  139. {
  140.  
  141. float theNetPay; // total take home pay (minus taxes)
  142. float theTotalTaxes; // total taxes owed
  143.  
  144. // calculate the total taxes owed
  145. theTotalTaxes = stateTax + fedTax;
  146.  
  147. // calculate the net pay
  148. theNetPay = grossPay - theTotalTaxes;
  149.  
  150. // return the calculated net pay
  151. return (theNetPay);
  152.  
  153. } // calcNetPay
  154.  
  155. public:
  156.  
  157. // public member functions that can be called
  158. // to access private data member items
  159.  
  160. // public no argument constructor with defaults
  161. Employee() {firstName=""; lastName=""; taxState="";
  162. clockNumber=0; wageRate=0; hours=0;}
  163.  
  164. // public constructor with arguments passed to it
  165. Employee (string myFirstName, string myLastName, string myTaxState,
  166. int myClockNumber, float myWageRate, float myHours);
  167.  
  168. ~Employee(); // destructor
  169.  
  170. // public getter function prototypes to retrieve private data
  171. string getFirstName();
  172. string getLastName();
  173. string getTaxState();
  174. int getClockNumber();
  175. float getWageRate();
  176. float getHours();
  177. float getOverTimeHrs();
  178. float getGrossPay();
  179. float getStateTax();
  180. float getFedTax();
  181. float getNetPay();
  182. // member function prototype to print an Employee object
  183. void printEmployee(Employee e); // passes an object
  184.  
  185. }; // class Employee
  186.  
  187. // constructor with arguments
  188. Employee::Employee (string myFirstName, string myLastName, string myTaxState,
  189. int myClockNumber, float myWageRate, float myHours)
  190. {
  191. // initialize all member data items
  192. firstName = myFirstName; // input
  193. lastName = myLastName; // input
  194.  
  195. // Convert myTaxState to uppercase if entered in lowercase
  196. if (std::islower(myTaxState[0]))
  197. myTaxState[0] = std::toupper(myTaxState[0]);
  198. if (std::islower(myTaxState[1]))
  199. myTaxState[1] = std::toupper(myTaxState[1]);
  200.  
  201. taxState = myTaxState; // input
  202. clockNumber = myClockNumber; // input
  203. wageRate = myWageRate; // input
  204. hours = myHours; // input
  205. overTimeHrs = calcOverTimeHrs(); // calculated overtime hours
  206. grossPay = calcGrossPay(); // calculated gross pay
  207. stateTax = calcStateTax(); // calculated state tax
  208. fedTax = calcFedTax(); // calculated federal tax
  209. netPay = calcNetPay(); // calculated net pay
  210.  
  211. } // Employee constructor
  212.  
  213. // Employee's destructor
  214. Employee::~Employee()
  215. {
  216. // nothing to print here, but could ...
  217. }
  218.  
  219. // A "getter" function that will retrieve the First Name
  220. string Employee::getFirstName() {
  221. return firstName;
  222. }
  223.  
  224. // A "getter" function that will retrieve the employee Last Name
  225. string Employee::getLastName() {
  226. return lastName;
  227. }
  228.  
  229. // A "getter" function that will retrieve the employee Tax State
  230. string Employee::getTaxState() {
  231. return taxState;
  232. }
  233.  
  234. // A "getter" function that will retrieve the employee Clock Number
  235. int Employee::getClockNumber() {
  236. return clockNumber;
  237. }
  238.  
  239. // A "getter" function that will retrieve the employee Wage Rate
  240. float Employee::getWageRate() {
  241. return wageRate;
  242. }
  243.  
  244. // A "getter" function that will retrieve the employee Hours Worked
  245. float Employee::getHours() {
  246. return hours;
  247. }
  248.  
  249. // A "getter" function that will retrieve the employee Overtime Hours
  250. float Employee::getOverTimeHrs() {
  251. return overTimeHrs;
  252. }
  253.  
  254. // A "getter" function that will retrieve the employee Gross Pay
  255. float Employee::getGrossPay() {
  256. return grossPay;
  257. }
  258.  
  259. // A "getter" function that will retrieve the employee state tax
  260. float Employee::getStateTax() {
  261. return stateTax;
  262. }
  263.  
  264. // A "getter" function that will retrieve the employee federal tax
  265. float Employee::getFedTax() {
  266. return fedTax;
  267. }
  268.  
  269. // A "getter" function that will retrieve the employee net pay
  270. float Employee::getNetPay() {
  271. return netPay;
  272. }
  273.  
  274.  
  275. // a member function to print out the info in a given Employee object
  276. void Employee::printEmployee(Employee e) {
  277.  
  278. // Display the entered input on the Employee
  279. cout<<"\n\n *** Entered Details are *** \n";
  280. cout<<"\n First Name: "<< e.getFirstName();
  281. cout<<"\n Last Name: "<< e.getLastName();
  282. cout<<"\n Tax State: "<< e.getTaxState();
  283. cout <<"\n Clock Number: "<< e.getClockNumber();
  284. cout <<"\n Wage Rate: "<< e.getWageRate ();
  285. cout <<"\n Hours: "<< e.getHours ();
  286.  
  287. // Display the calculated values of the Employee
  288. cout<<"\n\n *** Calculated Values are *** \n";
  289.  
  290. // print out overtime hours based on the employee information entered
  291. cout <<"\n Overtime Hours : " << e.getOverTimeHrs();
  292.  
  293. // print out gross pay based on the employee information entered
  294. cout <<"\n Gross Pay : $" << e.getGrossPay();
  295.  
  296. // print out state tax based on the employee information entered
  297. cout <<"\n State Tax : $" << e.getStateTax();
  298.  
  299. // print out federal tax based on the employee information entered
  300. cout <<"\n Federal Tax : $" << e.getFedTax();
  301.  
  302. // print out net pay based on the employee information entered
  303. cout <<"\n Net Pay : $" << e.getNetPay();
  304. // add a new line to separate the next employee
  305. cout <<"\n";
  306.  
  307. } // printEmployee
  308.  
  309. // main function to start the processing
  310. int main ()
  311. {
  312. // local variables to collect user input
  313.  
  314. string myFirstName; // First Name to input
  315. string myLastName; // Last Name to input
  316. string myTaxState; // Tax State to input
  317. int myClockNumber; // Clock Number to input
  318. float myWageRate; // Wage Rate to input
  319. float myHours; // Hours to input
  320.  
  321. cout << fixed // fix the number of decimal digits
  322. << setprecision(2); // to 2
  323.  
  324. // Array of Objects to store each of our employees
  325. Employee e[EMP_SIZE];
  326.  
  327. // prompt for information to read in employee information
  328. for (int i = 0; i < EMP_SIZE; ++i)
  329. {
  330. // Enter Employee Information
  331. cout <<"\n\n Enter Employee First Name: ";
  332. cin>>myFirstName ;
  333. cout <<"\n Enter Employee Last Name: ";
  334. cin>>myLastName ;
  335. cout <<"\n Enter Employee Tax State: ";
  336. cin>>myTaxState ;
  337. cout<<"\n Enter Employee Clock Number: ";
  338. cin>>myClockNumber;
  339. cout <<"\n Enter Employee Hourly Wage Rate: ";
  340. cin>>myWageRate;
  341. cout <<"\n Enter Employee Hours Worked for the Week: ";
  342. cin>>myHours;
  343.  
  344. // Call our constructor to create an employee object
  345. // using the input entered above. The constructor
  346. // will also put into motion the execution of the
  347. // various private member functions which will
  348. // calculate the overtime, gross pay, state tax, federal
  349. // tax, and net pay for the current employee.
  350.  
  351. // The updated object will be returned and placed in the
  352. // the element of our array of objects named "e", using the index
  353. // of the current value of our loop index "i" ... thus: e[i]
  354. e[i] = {myFirstName, myLastName, myTaxState,
  355. myClockNumber, myWageRate, myHours};
  356.  
  357. // Call the printEmployee public member function to display all
  358. // the inputted and calculated values for the current employee
  359. e[i].printEmployee(e[i]);
  360.  
  361. } // for
  362.  
  363. return 0;
  364.  
  365. } // main
Success #stdin #stdout 0s 5284KB
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