fork download
  1. //********************************************************
  2. //
  3. // Assignment 11 - Object Oriented Design
  4. //
  5. // Name: <replace with your name>
  6. //
  7. // Class: C Programming, <replace with Semester and Year>
  8. //
  9. // Date: <replace with the current date>
  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 FED_TAX_RATE 0.25
  37.  
  38. using namespace std;
  39.  
  40. // class Employee
  41. class Employee {
  42. private:
  43. string firstName; // Employee First Name
  44. string lastName; // Employee Last Name
  45. string taxState; // Employee Tax State
  46. int clockNumber; // Employee Clock Number
  47. float wageRate; // Hourly Wage Rate
  48. float hours; // Hours worked in a week
  49. float overTimeHrs; // Overtime Hours worked
  50. float grossPay; // Weekly Gross Pay
  51. float stateTax; // State Tax
  52. float fedTax; // Fed Tax
  53. float netPay; // Net Pay
  54.  
  55. float calcOverTimeHrs() {
  56. return (hours > STD_HOURS) ? (hours - STD_HOURS) : 0;
  57. }
  58.  
  59. float calcGrossPay() {
  60. return (overTimeHrs > 0)
  61. ? (STD_HOURS * wageRate + overTimeHrs * (wageRate * OT_RATE))
  62. : (hours * wageRate);
  63. }
  64.  
  65. float calcStateTax() {
  66. if (taxState == "MA") return grossPay * MA_TAX_RATE;
  67. if (taxState == "NH") return grossPay * NH_TAX_RATE;
  68. if (taxState == "VT") return grossPay * VT_TAX_RATE;
  69. if (taxState == "CA") return grossPay * CA_TAX_RATE;
  70. return grossPay * DEFAULT_TAX_RATE;
  71. }
  72.  
  73. float calcFedTax() {
  74. return grossPay * FED_TAX_RATE;
  75. }
  76.  
  77. float calcNetPay() {
  78. return grossPay - (stateTax + fedTax);
  79. }
  80.  
  81. public:
  82. Employee() : firstName(""), lastName(""), taxState(""), clockNumber(0), wageRate(0), hours(0) {}
  83.  
  84. Employee(string myFirstName, string myLastName, string myTaxState, int myClockNumber, float myWageRate, float myHours)
  85. : firstName(myFirstName), lastName(myLastName), clockNumber(myClockNumber), wageRate(myWageRate), hours(myHours) {
  86. if (islower(myTaxState[0])) myTaxState[0] = toupper(myTaxState[0]);
  87. if (islower(myTaxState[1])) myTaxState[1] = toupper(myTaxState[1]);
  88. taxState = myTaxState;
  89.  
  90. overTimeHrs = calcOverTimeHrs();
  91. grossPay = calcGrossPay();
  92. stateTax = calcStateTax();
  93. fedTax = calcFedTax();
  94. netPay = calcNetPay();
  95. }
  96.  
  97. string getFirstName() { return firstName; }
  98. string getLastName() { return lastName; }
  99. string getTaxState() { return taxState; }
  100. int getClockNumber() { return clockNumber; }
  101. float getWageRate() { return wageRate; }
  102. float getHours() { return hours; }
  103. float getOverTimeHrs() { return overTimeHrs; }
  104. float getGrossPay() { return grossPay; }
  105. float getStateTax() { return stateTax; }
  106. float getFedTax() { return fedTax; }
  107. float getNetPay() { return netPay; }
  108.  
  109. void printEmployee(Employee e) {
  110. cout << "\n\n *** Entered Details are *** \n";
  111. cout << "\n First Name: " << e.getFirstName();
  112. cout << "\n Last Name: " << e.getLastName();
  113. cout << "\n Tax State: " << e.getTaxState();
  114. cout << "\n Clock Number: " << e.getClockNumber();
  115. cout << "\n Wage Rate: " << e.getWageRate();
  116. cout << "\n Hours: " << e.getHours();
  117.  
  118. cout << "\n\n *** Calculated Values are *** \n";
  119. cout << "\n Overtime Hours : " << e.getOverTimeHrs();
  120. cout << "\n Gross Pay : $" << e.getGrossPay();
  121. cout << "\n State Tax : $" << e.getStateTax();
  122. cout << "\n Federal Tax : $" << e.getFedTax();
  123. cout << "\n Net Pay : $" << e.getNetPay();
  124. cout << "\n";
  125. }
  126. };
  127.  
  128. int main() {
  129. string myFirstName, myLastName, myTaxState;
  130. int myClockNumber;
  131. float myWageRate, myHours;
  132.  
  133. cout << fixed << setprecision(2);
  134.  
  135. Employee e[EMP_SIZE];
  136.  
  137. for (int i = 0; i < EMP_SIZE; ++i) {
  138. cout << "\n\n Enter Employee First Name: ";
  139. cin >> myFirstName;
  140. cout << "\n Enter Employee Last Name: ";
  141. cin >> myLastName;
  142. cout << "\n Enter Employee Tax State: ";
  143. cin >> myTaxState;
  144. cout << "\n Enter Employee Clock Number: ";
  145. cin >> myClockNumber;
  146. cout << "\n Enter Employee Hourly Wage Rate: ";
  147. cin >> myWageRate;
  148. cout << "\n Enter Employee Hours Worked for the Week: ";
  149. cin >> myHours;
  150.  
  151. e[i] = Employee(myFirstName, myLastName, myTaxState, myClockNumber, myWageRate, myHours);
  152.  
  153. e[i].printEmployee(e[i]);
  154. }
  155.  
  156. return 0;
  157. }
  158.  
Success #stdin #stdout 0.01s 5268KB
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