summaryrefslogtreecommitdiffstats
path: root/C++/Structs
diff options
context:
space:
mode:
authormsglm <msglm@techchud.xyz>2023-01-14 05:31:48 -0600
committermsglm <msglm@techchud.xyz>2023-01-14 05:31:48 -0600
commit9d53d8857eaa1c9405894a88ca75bc4657e42f35 (patch)
treeeb1efc1d028b949dd83bb710c68be8eff58f26e7 /C++/Structs
downloadschool-code-master.tar.gz
school-code-master.tar.bz2
school-code-master.zip
Inital CommitHEADmaster
Diffstat (limited to 'C++/Structs')
-rw-r--r--C++/Structs/INSTRUCTIONS44
-rw-r--r--C++/Structs/Structs.cpp112
-rw-r--r--C++/Structs/input.txt7
3 files changed, 163 insertions, 0 deletions
diff --git a/C++/Structs/INSTRUCTIONS b/C++/Structs/INSTRUCTIONS
new file mode 100644
index 0000000..29cba01
--- /dev/null
+++ b/C++/Structs/INSTRUCTIONS
@@ -0,0 +1,44 @@
+
+Project 5: Structs
+Due Friday, September 30th before midnight
+100 Points
+Create a program that uses a struct with array or vector variables that do the following:
+
+ Get the below information:
+ First Name
+ Last Name
+ Job Title
+ Employee Number
+ Hours Worked
+ Hourly Wage
+ Number of Deductions Claimed
+ Determine if the employee is entitled to overtime (see videos for explanation of overtime)
+ Determine tax rate based on deductions claimed (see videos for explanation of deductions)
+ Determine gross pay, taxes withheld, and netpay
+ Output all information to the screen, but only output overtime if the employee has it
+
+Assignment Notes:
+
+ You may get the data from the user via the keyboard or use an input file to read in an unknown number of records into your program. Your choice.
+ Also, you may also use vectors instead of arrays in your struct. Again, your choice
+ You should not ask the user for their tax rate, gross pay, net pay, or taxes withheld. Your program should do this for the user.
+ I expect to see functions for steps 1 - 5 above, however, you may combine functions if you wish to save space in your program
+
+General Notes:
+Be sure to use comments in your program: Name, Program Description, Date and anywhere else in the program you deem necessary.
+If you are stuck, I will help you!
+Grading Rubric:
+
+ If you do not include comments at the top of the program (name, program description, date), you will lose 15 points
+ If your program does not use functions, you will lose up to 50 points (depending on the number of functions missing)
+ If your program does not compile (run), then I will give a grade of 0/100. But will give you the change to repair for points back (some points are better than none)
+ If your program is late (within 48 hours of the due date), you will lose 25 points
+ If your program is late beyond the 48 hour due date, I will typically still accept it, but you will lose far more points. Depends on when you turn it in
+ If your program uses global variables, I will deduct 5 points for each used
+ If your program is not formatted nicely (code all over the place, ugly), you will lose up to 25 points depending on the extent
+ If your program stops working when I run it, you will lose points. The exact amount depends on the severity of the error
+ If your program still has your friend's name on it, I will send you a message asking you to try harder while giving you a 0/100
+ If your program looks like a a professional programmer wrote it, I will write to you to ask if you want a job. Well, maybe not. But, I will ask about the code
+ This is just a list of typical issues I run into when grading to give you some idea of where your points go. Points can be taken off for other reasons.
+
+
diff --git a/C++/Structs/Structs.cpp b/C++/Structs/Structs.cpp
new file mode 100644
index 0000000..e556264
--- /dev/null
+++ b/C++/Structs/Structs.cpp
@@ -0,0 +1,112 @@
+// Name: msglm
+// Date: Sep 29th, 2022
+// Program Name: Structs
+// Description: Given an input file, output gross pay, taxes, net pay, and other financial information.
+
+#include <iostream>
+#include <fstream>
+#include <string>
+using namespace std;
+
+
+//Structures
+struct Employee {
+ string fname;
+ string lname;
+ string job;
+ int employeeNum;
+ float hrsWorked;
+ float wage;
+ int deductions;
+};
+
+//Takes in the initalized file and turns it into a vector of arrays of strings
+Employee serializeIntoStruct(ifstream & fileVar) {
+ Employee temp;
+ getline(fileVar, temp.fname);
+ getline(fileVar, temp.lname);
+ getline(fileVar, temp.job);
+ fileVar >> temp.employeeNum;
+ fileVar >> temp.hrsWorked;
+ fileVar >> temp.wage;
+ fileVar >> temp.deductions;
+ return temp;
+}
+
+//given hours work, return the amount of overtime.
+float overtime(Employee employee) {
+ if (employee.hrsWorked > 40) {
+ float oTHours = employee.hrsWorked - 40;
+ if (oTHours > 0) {
+ return oTHours;
+ }
+ }
+ return 0;
+}
+
+//Given the deductions, return the taxrate
+float taxRate(Employee employee) {
+ if (employee.deductions <= 0) {
+ return 0.30;
+ } else if (0.30-(employee.deductions*0.05) <= 0.10) {
+ return 0.10;
+ } else {
+ return 0.30-(employee.deductions*0.05);
+ }
+}
+
+//Intake the employee in question, his overtime, and then the tax rate he's subject to
+//
+void outputGrossTaxPay(Employee employee, float overtime, float taxRate) {
+
+ float overtimePay = overtime*(employee.wage*1.5);
+ float normalPay;
+ if (overtime > 0) {
+ normalPay = employee.wage*40;
+ } else {
+ normalPay = employee.wage*employee.hrsWorked;
+ }
+ float grossPay = overtimePay + normalPay;
+ float withheld = taxRate*grossPay;
+ cout << "Employee Name: " << employee.fname << " " << employee.lname << endl;
+ cout << "Job Title: " << employee.job << endl;
+ cout << "Employee Number: " << employee.employeeNum << endl;
+ cout << "Hours Worked: " << employee.hrsWorked << endl;
+ cout << "Hourly Wage: $" << employee.wage << endl;
+ cout << "Deductions Claimed: " << employee.deductions << endl;
+ if (overtime > 0) {
+ cout << "Overtime Hours: " << overtime << endl;
+ cout << "Overtime Pay: $" << overtimePay << endl;
+ }
+ cout << "Gross Pay: $" << grossPay << endl;
+ cout << "Tax Withheld: $" << withheld << endl;
+ cout << "Net Pay: $" << grossPay-withheld << endl;
+
+
+
+}
+
+int main() {
+ //Variable declaration
+ ifstream fileVar;
+ fileVar.open("input.txt");
+
+ if (!fileVar) {
+ cout << "ERROR! input.txt failed to open!";
+ exit(1);
+ }
+
+ Employee readValues = serializeIntoStruct(fileVar);
+ outputGrossTaxPay(readValues, overtime(readValues), taxRate(readValues));
+
+
+
+}
+
+/*
+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License Version 3 ONLY as published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
diff --git a/C++/Structs/input.txt b/C++/Structs/input.txt
new file mode 100644
index 0000000..91705a5
--- /dev/null
+++ b/C++/Structs/input.txt
@@ -0,0 +1,7 @@
+Anonymous
+Anonymous
+IT Technician
+2450
+40
+14.50
+2