fork download
  1. //********************************************************************
  2. //
  3. // Assignment 11 - Object Oriented Design
  4. //
  5. // Name: <Adrian>
  6. //
  7. // Class: C Programming, <Fall 2026>
  8. //
  9. // Date: <November 23rd, 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. // 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. using namespace std;
  27.  
  28. // define constants
  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. class Employee
  48. {
  49. private:
  50.  
  51. // private data available only to member functions
  52. // all data is initialized to support creating instances that
  53. // are not done via a full constructor with data to be used
  54.  
  55. string firstName = ""; // Employee First Name
  56. string lastName = ""; // Employee Last Name
  57. string taxState = ""; // Employee Tax State
  58. int clockNumber = 0; // Employee Clock Number
  59. float wageRate = 0.0; // Hourly Wage Rate
  60. float hours = 0.0; // Hours worked in a week
  61. float overTimeHrs = 0.0; // Overtime Hours worked
  62. float grossPay = 0.0; // Weekly Gross Pay
  63. float stateTax = 0.0; // State Tax
  64. float fedTax = 0.0; // Fed Tax
  65. float netPay = 0.0; // Net Pay
  66.  
  67. // private functions for call only by an Employee object
  68. // ... these are generally more complex computations
  69.  
  70. float calcOverTimeHrs();
  71. float calcGrossPay();
  72. float calcStateTax();
  73. float calcFedTax();
  74. float calcNetPay();
  75.  
  76. // Declare "getter" function prototypes to retrieve private data
  77. // Note: The inline keyword is not required for the prototypes
  78.  
  79. string getFirstName();
  80. string getLastName();
  81. string getTaxState();
  82. int getClockNumber();
  83. float getWageRate();
  84. float getHours();
  85. float getOverTimeHrs();
  86. float getGrossPay();
  87.  
  88. // TODO - Declare a "getter" function declaration that will retrieve the employee stateTax
  89. float getStateTax();
  90.  
  91. // TODO - Declare a "getter" function declaration that will retrieve the employee fedTax
  92. float getFedTax();
  93.  
  94. // TODO - Declare a "getter" function declaration that will retrieve the employee netPay
  95. float getNetPay();
  96.  
  97. public:
  98.  
  99. // public member functions that can be called
  100. // to access private data member items
  101.  
  102. // public no argument constructor with defaults
  103. // All Employee class data will be initialized to defaults
  104. Employee() {}
  105.  
  106. // public constructor with arguments passed to it
  107. Employee (string myFirstName, string myLastName, string myTaxState,
  108. int myClockNumber, float myWageRate, float myHours);
  109.  
  110. ~Employee(); // destructor
  111.  
  112. // print out Employee data to the console
  113. void printEmployee();
  114.  
  115.  
  116. }; // End class declarations.
  117.  
  118. // The inlined Employee members follow...
  119.  
  120. // A "getter" function that will retrieve the First Name
  121. inline string Employee::getFirstName() {
  122. return firstName;
  123. }
  124.  
  125. // A "getter" function that will retrieve the employee Last Name
  126. inline string Employee::getLastName() {
  127. return lastName;
  128. }
  129.  
  130. // A "getter" function that will retrieve the employee Tax State
  131. inline string Employee::getTaxState() {
  132. return taxState;
  133. }
  134.  
  135. // A "getter" function that will retrieve the employee Clock Number
  136. inline int Employee::getClockNumber() {
  137. return clockNumber;
  138. }
  139.  
  140. // A "getter" function that will retrieve the employee Wage Rate
  141. inline float Employee::getWageRate() {
  142. return wageRate;
  143. }
  144.  
  145. // A "getter" function that will retrieve the employee Hours Worked
  146. inline float Employee::getHours() {
  147. return hours;
  148. }
  149.  
  150. // A "getter" function that will retrieve the employee Overtime Hours
  151. inline float Employee::getOverTimeHrs() {
  152. return overTimeHrs;
  153. }
  154.  
  155. // A "getter" function that will retrieve the employee Gross Pay
  156. inline float Employee::getGrossPay() {
  157. return grossPay;
  158. }
  159.  
  160. // TODO - Add an inline "getter" function that will retrieve the employee stateTax
  161. inline float Employee::getStateTax() {
  162. return stateTax;
  163. }
  164.  
  165. // TODO - Add an inline "getter" function that will retrieve the employee fedTax
  166. inline float Employee::getFedTax() {
  167. return fedTax;
  168. }
  169.  
  170. // TODO - Add an inline "getter" function that will retrieve the employee netPay
  171. inline float Employee::getNetPay() {
  172. return netPay;
  173. }
  174.  
  175.  
  176. // private member function to calculate Overtime Hours
  177. float Employee::calcOverTimeHrs ( )
  178. {
  179. // Calculate the overtime hours for the week
  180. if (hours > STD_HOURS)
  181. overTimeHrs = hours - STD_HOURS; // ot hours
  182. else
  183. overTimeHrs = 0; // no ot hours
  184.  
  185. // the calculated overtime hours
  186. return (overTimeHrs);
  187.  
  188. } // calcOverTimeHrs
  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. // private member function to calculate State Tax
  211. float Employee::calcStateTax ()
  212. {
  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. // private member function to calculate Federal Tax
  237. float Employee::calcFedTax ()
  238. {
  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. // private member function to calculate Net Pay
  251. float Employee::calcNetPay ()
  252. {
  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. // a member function to print out the info in a given Employee object
  302. void Employee::printEmployee() {
  303.  
  304. // Display the entered input on the Employee
  305. cout << endl << endl << " *** Entered Details are *** " << endl;
  306. cout << endl << " First Name: " << getFirstName();
  307. cout << endl << " Last Name: " << getLastName();
  308. cout << endl << " Tax State: " << getTaxState();
  309. cout << endl << " Clock Number: " << getClockNumber();
  310. cout << endl << " Wage Rate: " << getWageRate();
  311. cout << endl << " Hours: " << getHours();
  312.  
  313. // Display the calculated values of the Employee
  314. cout << endl << endl << " *** Calculated Values are *** " << endl;
  315.  
  316. // print out overtime hours based on the employee information entered
  317. cout << endl << " Overtime Hours : " << getOverTimeHrs();
  318.  
  319. // print out gross pay based on the employee information entered
  320. cout << endl << " Gross Pay : $" << getGrossPay();
  321.  
  322. // TODO - Add cout statement with call to stateTax getter function
  323. cout << endl << " State Tax : $" << getStateTax();
  324.  
  325. // TODO - Add cout statement with call to fedTax getter function
  326. cout << endl << " Federal Tax : $" << getFedTax();
  327.  
  328. // TODO - Add cout statement with call to netPay getter function
  329. cout << endl << " Net Pay : $" << getNetPay();
  330.  
  331. // add a new line to separate the next employee
  332. cout << endl << endl;
  333.  
  334. } // printEmployee
  335.  
  336. // Employee's destructor
  337. Employee::~Employee()
  338. {
  339. // nothing to print here, but could ...
  340. }
  341.  
  342.  
  343. // main function to start the processing
  344. int main ()
  345. {
  346. // local variables to collect user input
  347.  
  348. string myFirstName; // First Name to input
  349. string myLastName; // Last Name to input
  350. string myTaxState; // Tax State to input
  351. int myClockNumber; // Clock Number to input
  352. float myWageRate; // Wage Rate to input
  353. float myHours; // Hours to input
  354.  
  355. cout << fixed // fix the number of decimal digits
  356. << setprecision(2); // to 2
  357.  
  358. // Array of Objects to store each of our employees
  359. // This calls the default constructor for each array element
  360. Employee e[EMP_SIZE];
  361.  
  362. // prompt for information to read in employee information
  363. for (int i = 0; i < EMP_SIZE; ++i)
  364. {
  365. // Enter Employee Information
  366. cout << "\n Enter Employee First Name: ";
  367. cin >> myFirstName;
  368. cout << "\n Enter Employee Last Name: ";
  369. cin >> myLastName;
  370. cout << "\n Enter Employee Tax State: ";
  371. cin >> myTaxState;
  372. cout << "\n Enter Employee Clock Number: ";
  373. cin >> myClockNumber;
  374. cout << "\n Enter Employee Hourly Wage Rate: ";
  375. cin >> myWageRate;
  376. cout << "\n Enter Employee Hours Worked for the Week: ";
  377. cin >> myHours;
  378.  
  379. // Call our constructor to create an employee object
  380. // using the input entered above. The constructor
  381. // will also put into motion the execution of the
  382. // various private member functions which will
  383. // calculate the overtime, gross pay, state tax, federal
  384. // tax, and net pay for the current employee.
  385.  
  386. // The updated object will be returned and placed in the
  387. // the element of our array of objects named "e", using the index
  388. // of the current value of our loop index "i" ... thus: e[i]
  389. e[i] = {myFirstName, myLastName, myTaxState,
  390. myClockNumber, myWageRate, myHours
  391. };
  392.  
  393. // Call the printEmployee public member function to display all
  394. // the inputted and calculated values for the current employee
  395. e[i].printEmployee();
  396.  
  397. } // for
  398.  
  399. return 0;
  400.  
  401. } // main
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