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