fork download
  1. //********************************************************
  2. //
  3. // Assignment 11 - Object Oriented Design
  4. //
  5. // Name: Eric Dinh
  6. //
  7. // Class: C Programming, Fall 2026
  8. //
  9. // Date: 11/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> // 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. public:
  91.  
  92. // public member functions that can be called
  93. // to access private data member items
  94.  
  95. // public no argument constructor with defaults
  96. // All Employee class data will be initialized to defaults
  97. Employee() {}
  98.  
  99. // public constructor with arguments passed to it
  100. Employee (string myFirstName, string myLastName, string myTaxState,
  101. int myClockNumber, float myWageRate, float myHours);
  102.  
  103. ~Employee(); // destructor
  104.  
  105. // print out Employee data to the console
  106. void printEmployee();
  107.  
  108.  
  109. }; // End class declarations.
  110.  
  111. // The inlined Employee members follow...
  112.  
  113. // A "getter" function that will retrieve the First Name
  114. inline string Employee::getFirstName() {
  115. return firstName;
  116. }
  117.  
  118. // A "getter" function that will retrieve the employee Last Name
  119. inline string Employee::getLastName() {
  120. return lastName;
  121. }
  122.  
  123. // A "getter" function that will retrieve the employee Tax State
  124. inline string Employee::getTaxState() {
  125. return taxState;
  126. }
  127.  
  128. // A "getter" function that will retrieve the employee Clock Number
  129. inline int Employee::getClockNumber() {
  130. return clockNumber;
  131. }
  132.  
  133. // A "getter" function that will retrieve the employee Wage Rate
  134. inline float Employee::getWageRate() {
  135. return wageRate;
  136. }
  137.  
  138. // A "getter" function that will retrieve the employee Hours Worked
  139. inline float Employee::getHours() {
  140. return hours;
  141. }
  142.  
  143. // A "getter" function that will retrieve the employee Overtime Hours
  144. inline float Employee::getOverTimeHrs() {
  145. return overTimeHrs;
  146. }
  147.  
  148. // A "getter" function that will retrieve the employee Gross Pay
  149. inline float Employee::getGrossPay() {
  150. return grossPay;
  151. }
  152.  
  153. // A "getter" function that will retrieve the employee State Tax
  154. inline float Employee::getStateTax() {
  155. return stateTax;
  156. }
  157.  
  158. // A "getter" function that will retrieve the employee Federal Tax
  159. inline float Employee::getFedTax() {
  160. return fedTax;
  161. }
  162.  
  163. // A "getter" function that will retrieve the employee Net Pay
  164. inline float Employee::getNetPay() {
  165. return netPay;
  166. }
  167.  
  168.  
  169. // private member function to calculate Overtime Hours
  170. float Employee::calcOverTimeHrs ( )
  171. {
  172. // Calculate the overtime hours for the week
  173. if (hours > STD_HOURS)
  174. overTimeHrs = hours - STD_HOURS; // ot hours
  175. else
  176. overTimeHrs = 0; // no ot hours
  177.  
  178. // the calculated overtime hours
  179. return (overTimeHrs);
  180.  
  181. } // calcOverTimeHrs
  182.  
  183. // private member function to calculate Gross Pay
  184. float Employee::calcGrossPay ( )
  185. {
  186. // Process gross pay based on if there is overtime
  187. if (overTimeHrs > 0)
  188. {
  189. // overtime
  190. grossPay = (STD_HOURS * wageRate) // normal pay
  191. + (overTimeHrs * (wageRate * OT_RATE)); // ot pay
  192. }
  193. else // no overtime pay
  194. {
  195. grossPay = wageRate * hours; // normal pay
  196. }
  197.  
  198. // the calculated gross pay
  199. return (grossPay);
  200.  
  201. } // calcGrossPay
  202.  
  203. // private member function to calculate State Tax
  204. float Employee::calcStateTax ()
  205. {
  206.  
  207. float theStateTax; // calculated state tax
  208.  
  209. theStateTax = grossPay; // initialize to gross pay
  210.  
  211. // calculate state tax based on where employee resides
  212.  
  213. if (taxState.compare("MA") == 0)
  214. theStateTax *= MA_TAX_RATE;
  215. else if (taxState.compare("VT") == 0)
  216. theStateTax *= VT_TAX_RATE;
  217. else if (taxState.compare("NH") == 0)
  218. theStateTax *= NH_TAX_RATE;
  219. else if (taxState.compare("CA") == 0)
  220. theStateTax *= CA_TAX_RATE;
  221. else
  222. theStateTax *= DEFAULT_TAX_RATE; // any other state
  223.  
  224. // return the calculated state tax
  225. return (theStateTax);
  226.  
  227. } // calcStateTax
  228.  
  229. // private member function to calculate Federal Tax
  230. float Employee::calcFedTax ()
  231. {
  232.  
  233. float theFedTax; // The calculated Federal Tax
  234.  
  235. // Federal Tax is the same for all regardless of state
  236. theFedTax = grossPay * FED_TAX_RATE;
  237.  
  238. // return the calculated federal tax
  239. return (theFedTax);
  240.  
  241. } // calcFedTax
  242.  
  243. // private member function to calculate Net Pay
  244. float Employee::calcNetPay ()
  245. {
  246.  
  247. float theNetPay; // total take home pay (minus taxes)
  248. float theTotalTaxes; // total taxes owed
  249.  
  250. // calculate the total taxes owed
  251. theTotalTaxes = stateTax + fedTax;
  252.  
  253. // calculate the net pay
  254. theNetPay = grossPay - theTotalTaxes;
  255.  
  256. // return the calculated net pay
  257. return (theNetPay);
  258.  
  259. } // calcNetPay
  260.  
  261.  
  262. // constructor with arguments
  263. Employee::Employee (string myFirstName, string myLastName, string myTaxState,
  264. int myClockNumber, float myWageRate, float myHours)
  265. {
  266. // initialize all member data items
  267. firstName = myFirstName; // input
  268. lastName = myLastName; // input
  269.  
  270. // Convert myTaxState to uppercase if entered in lowercase
  271. if (std::islower(myTaxState[0]))
  272. myTaxState[0] = std::toupper(myTaxState[0]);
  273. if (std::islower(myTaxState[1]))
  274. myTaxState[1] = std::toupper(myTaxState[1]);
  275.  
  276. taxState = myTaxState; // input
  277. clockNumber = myClockNumber; // input
  278. wageRate = myWageRate; // input
  279. hours = myHours; // input
  280. overTimeHrs = calcOverTimeHrs(); // calculated overtime hours
  281. grossPay = calcGrossPay(); // calculated gross pay
  282. stateTax = calcStateTax(); // calculated state tax
  283. fedTax = calcFedTax(); // calculated federal tax
  284. netPay = calcNetPay(); // calculated net pay
  285.  
  286. } // Employee constructor
  287.  
  288. // a member function to print out the info in a given Employee object
  289. void Employee::printEmployee() {
  290.  
  291. // Display the entered input on the Employee
  292. cout << endl << endl <<"*** Entered Details are *** " << endl;
  293. cout << endl <<" First Name: "<< getFirstName();
  294. cout << endl <<" Last Name: "<< getLastName();
  295. cout << endl <<" Tax State: "<< getTaxState();
  296. cout << endl <<" Clock Number: "<< getClockNumber();
  297. cout << endl <<" Wage Rate: "<< getWageRate ();
  298. cout << endl <<" Hours: "<< getHours ();
  299.  
  300. // Display the calculated values of the Employee
  301. cout<< endl << endl <<" *** Calculated Values are *** " << endl;
  302.  
  303. // print out overtime hours based on the employee information entered
  304. cout << endl << " Overtime Hours : " << getOverTimeHrs();
  305.  
  306. // print out gross pay based on the employee information entered
  307. cout << endl << " Gross Pay : $" << getGrossPay();
  308.  
  309. // print out state tax based on the employee information entered
  310. cout << endl << " State Tax : $" << getStateTax();
  311.  
  312. // print out federal tax based on the employee information entered
  313. cout << endl << " Federal Tax : $" << getFedTax();
  314.  
  315. // print out net pay based on the employee information entered
  316. cout << endl << " Net Pay : $" << getNetPay();
  317.  
  318. // add a new line to separate the next employee
  319. cout <<"\n";
  320.  
  321. } // printEmployee
  322.  
  323. // Employee's destructor
  324. Employee::~Employee()
  325. {
  326. // nothing to print here, but could ...
  327. }
  328.  
  329.  
  330. // main function to start the processing
  331. int main ()
  332. {
  333. // local variables to collect user input
  334.  
  335. string myFirstName; // First Name to input
  336. string myLastName; // Last Name to input
  337. string myTaxState; // Tax State to input
  338. int myClockNumber; // Clock Number to input
  339. float myWageRate; // Wage Rate to input
  340. float myHours; // Hours to input
  341.  
  342. cout << fixed // fix the number of decimal digits
  343. << setprecision(2); // to 2
  344.  
  345. // Array of Objects to store each of our employees
  346. // This calls the default constructor for each array element
  347. Employee e[EMP_SIZE];
  348.  
  349. // prompt for information to read in employee information
  350. for (int i = 0; i < EMP_SIZE; ++i)
  351. {
  352. // Enter Employee Information
  353. cout <<"\n\n Enter Employee First Name: ";
  354. cin>>myFirstName ;
  355. cout <<"\n Enter Employee Last Name: ";
  356. cin>>myLastName ;
  357. cout <<"\n Enter Employee Tax State: ";
  358. cin>>myTaxState ;
  359. cout<<"\n Enter Employee Clock Number: ";
  360. cin>>myClockNumber;
  361. cout <<"\n Enter Employee Hourly Wage Rate: ";
  362. cin>>myWageRate;
  363. cout <<"\n Enter Employee Hours Worked for the Week: ";
  364. cin>>myHours;
  365.  
  366. // Call our constructor to create an employee object
  367. // using the input entered above. The constructor
  368. // will also put into motion the execution of the
  369. // various private member functions which will
  370. // calculate the overtime, gross pay, state tax, federal
  371. // tax, and net pay for the current employee.
  372.  
  373. // The updated object will be returned and placed in the
  374. // the element of our array of objects named "e", using the index
  375. // of the current value of our loop index "i" ... thus: e[i]
  376. e[i] = {myFirstName, myLastName, myTaxState,
  377. myClockNumber, myWageRate, myHours
  378. };
  379.  
  380. // Call the printEmployee public member function to display all
  381. // the inputted and calculated values for the current employee
  382. e[i].printEmployee();
  383.  
  384. } // for
  385.  
  386. return 0;
  387.  
  388. } // 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