fork download
  1. //********************************************************
  2. //
  3. // Assignment 11 - Object Oriented Design
  4. //
  5. // Name: <Lavender Jane Siaw>
  6. //
  7. // Class: C Programming, <Spring 2026>
  8. //
  9. // Date: <5-1-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> // 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 gernally more complex computations
  70. float calcOverTimeHrs();
  71. float calcGrossPay();
  72. float calcStateTax();
  73. float calcFedTax();
  74. float calcNetPay();
  75.  
  76. // Delcare "getter" function prototypes to retrieve private data
  77. // Note: The inline keyword is not required 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. float getStateTax();
  87. float getFedTax();
  88. float getNetPay();
  89.  
  90.  
  91. // TODO - Declare a "getter" function declaration that will retrieve the employee stateTax
  92.  
  93. // TODO - Declare a "getter" function declaration that will retrieve the employee fedTax
  94.  
  95. // TODO - Declare a "getter" function declaration that will retrieve the employee netPay
  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. inline float Employee::getStateTax() {
  160. return stateTax; }
  161.  
  162. inline float Employee::getFedTax() {
  163. return fedTax; }
  164.  
  165.  
  166. inline float Employee::getNetPay() {
  167. return netPay;
  168. }
  169.  
  170. // TODO - Add an inline "getter" function that will retrieve the employee stateTax
  171.  
  172. // TODO - Add an inline "getter" function that will retrieve the employee fedTax
  173.  
  174. // TODO - Add an inline "getter" function that will retrieve the employee netPay
  175.  
  176.  
  177. // private member function to calculate Overtime Hours
  178. float Employee::calcOverTimeHrs ( )
  179. {
  180. // Calculate the overtime hours for the week
  181. if (hours > STD_HOURS)
  182. overTimeHrs = hours - STD_HOURS; // ot hours
  183. else
  184. overTimeHrs = 0; // no ot hours
  185.  
  186. // the calculated overtime hours
  187. return (overTimeHrs);
  188.  
  189. } // calcOverTimeHrs
  190.  
  191. // private member function to calculate Gross Pay
  192. float Employee::calcGrossPay ( )
  193. {
  194. // Process gross pay based on if there is overtime
  195. if (overTimeHrs > 0)
  196. {
  197. // overtime
  198. grossPay = (STD_HOURS * wageRate) // normal pay
  199. + (overTimeHrs * (wageRate * OT_RATE)); // ot pay
  200. }
  201. else // no overtime pay
  202. {
  203. grossPay = wageRate * hours; // normal pay
  204. }
  205.  
  206. // the calculated gross pay
  207. return (grossPay);
  208.  
  209. } // calcGrossPay
  210.  
  211. // private member function to calculate State Tax
  212. float Employee::calcStateTax ()
  213. {
  214.  
  215. float theStateTax; // calculated state tax
  216.  
  217. theStateTax = grossPay; // initialize to gross pay
  218.  
  219. // calculate state tax based on where employee resides
  220.  
  221. if (taxState.compare("MA") == 0)
  222. theStateTax *= MA_TAX_RATE;
  223. else if (taxState.compare("VT") == 0)
  224. theStateTax *= VT_TAX_RATE;
  225. else if (taxState.compare("NH") == 0)
  226. theStateTax *= NH_TAX_RATE;
  227. else if (taxState.compare("CA") == 0)
  228. theStateTax *= CA_TAX_RATE;
  229. else
  230. theStateTax *= DEFAULT_TAX_RATE; // any other state
  231.  
  232. // return the calculated state tax
  233. return (theStateTax);
  234.  
  235. } // calcStateTax
  236.  
  237. // private member function to calculate Federal Tax
  238. float Employee::calcFedTax ()
  239. {
  240.  
  241. float theFedTax; // The calculated Federal Tax
  242.  
  243. // Federal Tax is the same for all regardless of state
  244. theFedTax = grossPay * FED_TAX_RATE;
  245.  
  246. // return the calculated federal tax
  247. return (theFedTax);
  248.  
  249. } // calcFedTax
  250.  
  251. // private member function to calculate Net Pay
  252. float Employee::calcNetPay ()
  253. {
  254.  
  255. float theNetPay; // total take home pay (minus taxes)
  256. float theTotalTaxes; // total taxes owed
  257.  
  258. // calculate the total taxes owed
  259. theTotalTaxes = stateTax + fedTax;
  260.  
  261. // calculate the net pay
  262. theNetPay = grossPay - theTotalTaxes;
  263.  
  264. // return the calculated net pay
  265. return (theNetPay);
  266.  
  267. } // calcNetPay
  268.  
  269.  
  270. // constructor with arguments
  271. Employee::Employee (string myFirstName, string myLastName, string myTaxState,
  272. int myClockNumber, float myWageRate, float myHours)
  273. {
  274. // initialize all member data items
  275. firstName = myFirstName; // input
  276. lastName = myLastName; // input
  277.  
  278. // Convert myTaxState to uppercase if entered in lowercase
  279. if (std::islower(myTaxState[0]))
  280. myTaxState[0] = std::toupper(myTaxState[0]);
  281. if (std::islower(myTaxState[1]))
  282. myTaxState[1] = std::toupper(myTaxState[1]);
  283.  
  284. taxState = myTaxState; // input
  285. clockNumber = myClockNumber; // input
  286. wageRate = myWageRate; // input
  287. hours = myHours; // input
  288. overTimeHrs = calcOverTimeHrs(); // calculated overtime hours
  289. grossPay = calcGrossPay(); // calculated gross pay
  290. stateTax = calcStateTax(); // calculated state tax
  291. fedTax = calcFedTax(); // calculated fed tax
  292. netPay = calcNetPay(); // calculated net pay
  293.  
  294. // TODO - set stateTax as the return from calcStateTax member function
  295.  
  296. // TODO - set fedTax as the return from calcFedTax member function
  297.  
  298. // TODO - set netPay as the return from calcNetPay member function
  299.  
  300. } // Employee constructor
  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 state tax based on the employee information entered
  321. cout << endl << " State Tax : $" << getStateTax();
  322.  
  323. // print out gross pay based on the employee information entered
  324. cout << endl << " Gross Pay : $" << getGrossPay();
  325.  
  326. // print out fed tax based on the employee information entered
  327. cout << endl << " Fed Tax : $" << getFedTax();
  328.  
  329. // print out net pay based on the employee information entered
  330. cout << endl << " Net Pay : $" << getNetPay();
  331.  
  332.  
  333.  
  334. // TODO - Add cout statement with call to stateTax getter function
  335.  
  336. // TODO - Add cout statement with call to fedTax getter function
  337.  
  338. // TODO - Add cout statement with call to netPay getter function
  339.  
  340. // add a new line to separate the next employee
  341. cout <<"\n";
  342.  
  343. } // printEmployee
  344.  
  345. // Employee's destructor
  346. Employee::~Employee()
  347. {
  348. // nothing to print here, but could ...
  349. }
  350.  
  351.  
  352. // main function to start the processing
  353. int main ()
  354. {
  355. // local variables to collect user input
  356.  
  357. string myFirstName; // First Name to input
  358. string myLastName; // Last Name to input
  359. string myTaxState; // Tax State to input
  360. int myClockNumber; // Clock Number to input
  361. float myWageRate; // Wage Rate to input
  362. float myHours; // Hours to input
  363.  
  364. cout << fixed // fix the number of decimal digits
  365. << setprecision(2); // to 2
  366.  
  367. // Array of Objects to store each of our employees
  368. // This calls the default constructor for each array element
  369. Employee e[EMP_SIZE];
  370.  
  371. // prompt for information to read in employee information
  372. for (int i = 0; i < EMP_SIZE; ++i)
  373. {
  374. // Enter Employee Information
  375. cout <<"\n\n Enter Employee First Name: ";
  376. cin>>myFirstName ;
  377. cout <<"\n Enter Employee Last Name: ";
  378. cin>>myLastName ;
  379. cout <<"\n Enter Employee Tax State: ";
  380. cin>>myTaxState ;
  381. cout<<"\n Enter Employee Clock Number: ";
  382. cin>>myClockNumber;
  383. cout <<"\n Enter Employee Hourly Wage Rate: ";
  384. cin>>myWageRate;
  385. cout <<"\n Enter Employee Hours Worked for the Week: ";
  386. cin>>myHours;
  387.  
  388. // Call our constructor to create an employee object
  389. // using the input entered above. The constructor
  390. // will also put into motion the execution of the
  391. // various private member functions which will
  392. // calculate the overtime, gross pay, state tax, federal
  393. // tax, and net pay for the current employee.
  394.  
  395. // The updated object will be returned and placed in the
  396. // the element of our array of objects named "e", using the index
  397. // of the current value of our loop index "i" ... thus: e[i]
  398. e[i] = {myFirstName, myLastName, myTaxState,
  399. myClockNumber, myWageRate, myHours
  400. };
  401.  
  402. // Call the printEmployee public member function to display all
  403. // the inputted and calculated values for the current employee
  404. e[i].printEmployee();
  405.  
  406. } // for
  407.  
  408. return 0;
  409.  
  410. } // main
Success #stdin #stdout 0.01s 5280KB
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
 State Tax : $29.95
 Gross Pay : $598.90
 Fed 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
 State Tax : $0.00
 Gross Pay : $426.56
 Fed 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
 State Tax : $23.31
 Gross Pay : $388.50
 Fed 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
 State Tax : $46.55
 Gross Pay : $581.88
 Fed 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
 State Tax : $23.38
 Gross Pay : $334.00
 Fed Tax : $83.50
 Net Pay : $227.12