fork(1) 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 processes a 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. // Object-Oriented Design (using C++)
  19. //
  20. ********************************************************/
  21.  
  22. #include <iomanip> // std::setprecision, std::setw
  23. #include <iostream> // std::cout, std::fixed
  24. #include <string> // string functions
  25.  
  26. // define constants
  27. #define EMP_SIZE 5
  28. #define STD_HOURS 40.0
  29. #define OT_RATE 1.5
  30. #define MA_TAX_RATE 0.05
  31. #define NH_TAX_RATE 0.0
  32. #define VT_TAX_RATE 0.06
  33. #define CA_TAX_RATE 0.07
  34. #define DEFAULT_TAX_RATE 0.08
  35. #define FED_TAX_RATE 0.25
  36.  
  37. using namespace std;
  38.  
  39. // class Employee
  40. class Employee {
  41. private:
  42. string firstName; // Employee First Name
  43. string lastName; // Employee Last Name
  44. string taxState; // Employee Tax State
  45. int clockNumber; // Employee Clock Number
  46. float wageRate; // Hourly Wage Rate
  47. float hours; // Hours worked in a week
  48. float overTimeHrs; // Overtime Hours worked
  49. float grossPay; // Weekly Gross Pay
  50. float stateTax; // State Tax
  51. float fedTax; // Fed Tax
  52. float netPay; // Net Pay
  53.  
  54. float calcOverTimeHrs() {
  55. return (hours > STD_HOURS) ? (hours - STD_HOURS) : 0;
  56. }
  57.  
  58. float calcGrossPay() {
  59. return (overTimeHrs > 0) ?
  60. (STD_HOURS * wageRate + overTimeHrs * (wageRate * OT_RATE)) :
  61. (wageRate * hours);
  62. }
  63.  
  64. float calcStateTax() {
  65. if (taxState == "MA") return grossPay * MA_TAX_RATE;
  66. if (taxState == "VT") return grossPay * VT_TAX_RATE;
  67. if (taxState == "NH") return grossPay * NH_TAX_RATE;
  68. if (taxState == "CA") return grossPay * CA_TAX_RATE;
  69. return grossPay * DEFAULT_TAX_RATE;
  70. }
  71.  
  72. float calcFedTax() {
  73. return grossPay * FED_TAX_RATE;
  74. }
  75.  
  76. float calcNetPay() {
  77. return grossPay - (stateTax + fedTax);
  78. }
  79.  
  80. public:
  81. Employee() : firstName(""), lastName(""), taxState(""), clockNumber(0), wageRate(0), hours(0),
  82. overTimeHrs(0), grossPay(0), stateTax(0), fedTax(0), netPay(0) {}
  83.  
  84. Employee(string myFirstName, string myLastName, string myTaxState,
  85. int myClockNumber, float myWageRate, float myHours)
  86. : firstName(myFirstName), lastName(myLastName), clockNumber(myClockNumber),
  87. wageRate(myWageRate), hours(myHours) {
  88. // Normalize taxState to uppercase
  89. for (auto &c : myTaxState) c = toupper(c);
  90. taxState = myTaxState;
  91.  
  92. overTimeHrs = calcOverTimeHrs();
  93. grossPay = calcGrossPay();
  94. stateTax = calcStateTax();
  95. fedTax = calcFedTax();
  96. netPay = calcNetPay();
  97. }
  98.  
  99. ~Employee() {}
  100.  
  101. string getFirstName() { return firstName; }
  102. string getLastName() { return lastName; }
  103. string getTaxState() { return taxState; }
  104. int getClockNumber() { return clockNumber; }
  105. float getWageRate() { return wageRate; }
  106. float getHours() { return hours; }
  107. float getOverTimeHrs() { return overTimeHrs; }
  108. float getGrossPay() { return grossPay; }
  109. float getStateTax() { return stateTax; }
  110. float getFedTax() { return fedTax; }
  111. float getNetPay() { return netPay; }
  112.  
  113. void printEmployee() {
  114. cout << "\n\n *** Entered Details are *** \n";
  115. cout << "\n First Name: " << getFirstName();
  116. cout << "\n Last Name: " << getLastName();
  117. cout << "\n Tax State: " << getTaxState();
  118. cout << "\n Clock Number: " << getClockNumber();
  119. cout << "\n Wage Rate: $" << getWageRate();
  120. cout << "\n Hours Worked: " << getHours();
  121.  
  122. cout << "\n\n *** Calculated Values are *** \n";
  123. cout << "\n Overtime Hours: " << getOverTimeHrs();
  124. cout << "\n Gross Pay: $" << getGrossPay();
  125. cout << "\n State Tax: $" << getStateTax();
  126. cout << "\n Federal Tax: $" << getFedTax();
  127. cout << "\n Net Pay: $" << getNetPay();
  128. cout << "\n";
  129. }
  130. };
  131.  
  132. int main() {
  133. string myFirstName, myLastName, myTaxState;
  134. int myClockNumber;
  135. float myWageRate, myHours;
  136.  
  137. cout << fixed << setprecision(2);
  138.  
  139. Employee e[EMP_SIZE];
  140.  
  141. for (int i = 0; i < EMP_SIZE; ++i) {
  142. cout << "\n\n Enter Employee First Name: ";
  143. cin >> myFirstName;
  144. cout << "\n Enter Employee Last Name: ";
  145. cin >> myLastName;
  146. cout << "\n Enter Employee Tax State: ";
  147. cin >> myTaxState;
  148. cout << "\n Enter Employee Clock Number: ";
  149. cin >> myClockNumber;
  150. cout << "\n Enter Employee Hourly Wage Rate: ";
  151. cin >> myWageRate;
  152. cout << "\n Enter Employee Hours Worked for the Week: ";
  153. cin >> myHours;
  154.  
  155. e[i] = Employee(myFirstName, myLastName, myTaxState, myClockNumber, myWageRate, myHours);
  156.  
  157. e[i].printEmployee();
  158. }
  159.  
  160. return 0;
  161. }
  162.  
Success #stdin #stdout 0s 5292KB
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 Worked: 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 Worked: 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 Worked: 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 Worked: 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 Worked: 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