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