fork download
  1. //********************************************************
  2. //
  3. // Assignment 11 - Object Oriented Design
  4. //
  5. // Name: <Amir Gharouadi>
  6. //
  7. // Class: C Programming, <Spring 2026>
  8. //
  9. // Date: <04/23/2026>
  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>
  24. #include <iostream>
  25. #include <string>
  26.  
  27. using namespace std;
  28.  
  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. #define EMP_SIZE 5
  43.  
  44. using std::string;
  45.  
  46. class Employee
  47. {
  48. private:
  49. string firstName = "";
  50. string lastName = "";
  51. string taxState = "";
  52. int clockNumber = 0;
  53. float wageRate = 0.0;
  54. float hours = 0.0;
  55. float overTimeHrs = 0.0;
  56. float grossPay = 0.0;
  57. float stateTax = 0.0;
  58. float fedTax = 0.0;
  59. float netPay = 0.0;
  60.  
  61. float calcOverTimeHrs();
  62. float calcGrossPay();
  63. float calcStateTax();
  64. float calcFedTax();
  65. float calcNetPay();
  66.  
  67. string getFirstName();
  68. string getLastName();
  69. string getTaxState();
  70. int getClockNumber();
  71. float getWageRate();
  72. float getHours();
  73. float getOverTimeHrs();
  74. float getGrossPay();
  75.  
  76. float getStateTax();
  77. float getFedTax();
  78. float getNetPay();
  79.  
  80. public:
  81. Employee() {}
  82.  
  83. Employee(string myFirstName, string myLastName, string myTaxState,
  84. int myClockNumber, float myWageRate, float myHours);
  85.  
  86. ~Employee();
  87.  
  88. void printEmployee();
  89.  
  90. };
  91.  
  92. inline string Employee::getFirstName() {
  93. return firstName;
  94. }
  95.  
  96. inline string Employee::getLastName() {
  97. return lastName;
  98. }
  99.  
  100. inline string Employee::getTaxState() {
  101. return taxState;
  102. }
  103.  
  104. inline int Employee::getClockNumber() {
  105. return clockNumber;
  106. }
  107.  
  108. inline float Employee::getWageRate() {
  109. return wageRate;
  110. }
  111.  
  112. inline float Employee::getHours() {
  113. return hours;
  114. }
  115.  
  116. inline float Employee::getOverTimeHrs() {
  117. return overTimeHrs;
  118. }
  119.  
  120. inline float Employee::getGrossPay() {
  121. return grossPay;
  122. }
  123.  
  124. inline float Employee::getStateTax() {
  125. return stateTax;
  126. }
  127.  
  128. inline float Employee::getFedTax() {
  129. return fedTax;
  130. }
  131.  
  132. inline float Employee::getNetPay() {
  133. return netPay;
  134. }
  135.  
  136. float Employee::calcOverTimeHrs()
  137. {
  138. if (hours > STD_HOURS)
  139. overTimeHrs = hours - STD_HOURS;
  140. else
  141. overTimeHrs = 0;
  142.  
  143. return overTimeHrs;
  144. }
  145.  
  146. float Employee::calcGrossPay()
  147. {
  148. if (overTimeHrs > 0)
  149. {
  150. grossPay = (STD_HOURS * wageRate)
  151. + (overTimeHrs * (wageRate * OT_RATE));
  152. }
  153. else
  154. {
  155. grossPay = wageRate * hours;
  156. }
  157.  
  158. return grossPay;
  159. }
  160.  
  161. float Employee::calcStateTax()
  162. {
  163. float theStateTax;
  164.  
  165. theStateTax = grossPay;
  166.  
  167. if (taxState.compare("MA") == 0)
  168. theStateTax *= MA_TAX_RATE;
  169. else if (taxState.compare("VT") == 0)
  170. theStateTax *= VT_TAX_RATE;
  171. else if (taxState.compare("NH") == 0)
  172. theStateTax *= NH_TAX_RATE;
  173. else if (taxState.compare("CA") == 0)
  174. theStateTax *= CA_TAX_RATE;
  175. else
  176. theStateTax *= DEFAULT_TAX_RATE;
  177.  
  178. return theStateTax;
  179. }
  180.  
  181. float Employee::calcFedTax()
  182. {
  183. float theFedTax;
  184.  
  185. theFedTax = grossPay * FED_TAX_RATE;
  186.  
  187. return theFedTax;
  188. }
  189.  
  190. float Employee::calcNetPay()
  191. {
  192. float theNetPay;
  193. float theTotalTaxes;
  194.  
  195. theTotalTaxes = stateTax + fedTax;
  196.  
  197. theNetPay = grossPay - theTotalTaxes;
  198.  
  199. return theNetPay;
  200. }
  201.  
  202. Employee::Employee(string myFirstName, string myLastName, string myTaxState,
  203. int myClockNumber, float myWageRate, float myHours)
  204. {
  205. firstName = myFirstName;
  206. lastName = myLastName;
  207.  
  208. if (std::islower(myTaxState[0]))
  209. myTaxState[0] = std::toupper(myTaxState[0]);
  210. if (std::islower(myTaxState[1]))
  211. myTaxState[1] = std::toupper(myTaxState[1]);
  212.  
  213. taxState = myTaxState;
  214. clockNumber = myClockNumber;
  215. wageRate = myWageRate;
  216. hours = myHours;
  217. overTimeHrs = calcOverTimeHrs();
  218. grossPay = calcGrossPay();
  219.  
  220. stateTax = calcStateTax();
  221. fedTax = calcFedTax();
  222. netPay = calcNetPay();
  223.  
  224. }
  225.  
  226. void Employee::printEmployee() {
  227.  
  228. cout << endl << endl <<"*** Entered Details are *** " << endl;
  229. cout << endl <<" First Name: "<< getFirstName();
  230. cout << endl <<" Last Name: "<< getLastName();
  231. cout << endl <<" Tax State: "<< getTaxState();
  232. cout << endl <<" Clock Number: "<< getClockNumber();
  233. cout << endl <<" Wage Rate: "<< getWageRate();
  234. cout << endl <<" Hours: "<< getHours();
  235.  
  236. cout<< endl << endl <<" *** Calculated Values are *** " << endl;
  237.  
  238. cout << endl << " Overtime Hours : " << getOverTimeHrs();
  239.  
  240. cout << endl << " Gross Pay : $" << getGrossPay();
  241.  
  242. cout << endl << " State Tax : $" << getStateTax();
  243.  
  244. cout << endl << " Federal Tax : $" << getFedTax();
  245.  
  246. cout << endl << " Net Pay : $" << getNetPay();
  247.  
  248. cout <<"\n";
  249.  
  250. }
  251.  
  252. Employee::~Employee()
  253. {
  254. }
  255.  
  256. int main()
  257. {
  258. string myFirstName;
  259. string myLastName;
  260. string myTaxState;
  261. int myClockNumber;
  262. float myWageRate;
  263. float myHours;
  264.  
  265. cout << fixed
  266. << setprecision(2);
  267.  
  268. Employee e[EMP_SIZE];
  269.  
  270. for (int i = 0; i < EMP_SIZE; ++i)
  271. {
  272. cout <<"\n\n Enter Employee First Name: ";
  273. cin>>myFirstName;
  274. cout <<"\n Enter Employee Last Name: ";
  275. cin>>myLastName;
  276. cout <<"\n Enter Employee Tax State: ";
  277. cin>>myTaxState;
  278. cout<<"\n Enter Employee Clock Number: ";
  279. cin>>myClockNumber;
  280. cout <<"\n Enter Employee Hourly Wage Rate: ";
  281. cin>>myWageRate;
  282. cout <<"\n Enter Employee Hours Worked for the Week: ";
  283. cin>>myHours;
  284.  
  285. e[i] = {myFirstName, myLastName, myTaxState,
  286. myClockNumber, myWageRate, myHours
  287. };
  288.  
  289. e[i].printEmployee();
  290.  
  291. }
  292.  
  293. return 0;
  294.  
  295. }
Success #stdin #stdout 0.01s 5320KB
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