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