summaryrefslogtreecommitdiffstats
path: root/C++/OOP
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++/OOP
downloadschool-code-master.tar.gz
school-code-master.tar.bz2
school-code-master.zip
Inital CommitHEADmaster
Diffstat (limited to 'C++/OOP')
-rw-r--r--C++/OOP/INSTRUCTIONS43
-rw-r--r--C++/OOP/OOP.cpp205
2 files changed, 248 insertions, 0 deletions
diff --git a/C++/OOP/INSTRUCTIONS b/C++/OOP/INSTRUCTIONS
new file mode 100644
index 0000000..8c199c2
--- /dev/null
+++ b/C++/OOP/INSTRUCTIONS
@@ -0,0 +1,43 @@
+ Covert your Project 5 - Structs program to be object-oriented.
+Create a program that uses a class with array variables that do the following:
+
+ Get 3 sets of employee information for the below via the keyboard - no input file this time:
+ 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
+ Determine the highest and lowest paid employees. Output the name and salary of both
+
+Assignment Notes:
+
+ No structs please. Make your all of variables as private in the class to show me you understand how to do this
+ You may use vectors or array variables to store the employee data
+ 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 - 6 above
+
+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 is not object-oriented, you will lose up to 80 points (OOP is the goal of this assignment)
+ If your program does not use functions, you will lose up to 60 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 you use global variables in your program, 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++/OOP/OOP.cpp b/C++/OOP/OOP.cpp
new file mode 100644
index 0000000..76d5735
--- /dev/null
+++ b/C++/OOP/OOP.cpp
@@ -0,0 +1,205 @@
+// 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;
+
+
+//Classes
+class Employee {
+ private: //Hiding data from a programmer is like hiding pipes from a plumber
+ string fname;
+ string lname;
+ string job;
+ int employeeNum;
+ float hrsWorked;
+ float wage;
+ int deductions;
+ public:
+
+ //Lines and lines of the same thing
+ //I'm a stickler for verbosity in code, but this is just too far
+ //Brings me back to my Java days
+
+ void set_fname(string input) {
+ fname = input;
+ }
+ string get_fname() {
+ return fname;
+ }
+
+ void set_lname(string input) {
+ lname = input;
+ }
+ string get_lname() {
+ return lname;
+ }
+
+ void set_job(string input) {
+ job = input;
+ }
+ string get_job() {
+ return job;
+ }
+
+ void set_employeeNum(int input) {
+ employeeNum = input;
+ }
+ int get_employeeNum() {
+ return employeeNum;
+ }
+
+ void set_hrsWorked(float input) {
+ hrsWorked = input;
+ }
+ float get_hrsWorked() {
+ return hrsWorked;
+ }
+
+ void set_wage(float input) {
+ wage = input;
+ }
+ float get_wage() {
+ return wage;
+ }
+
+ void set_deductions(int input) {
+ deductions = input;
+ }
+ int get_deductions() {
+ return deductions;
+ }
+
+
+};
+
+
+//Takes in the initalized file and puts it into an object instance
+Employee serializeIntoObj() {
+ Employee employee;
+ string temp;
+
+ //Probably the worst thing I've ever wrote
+ //however, I am running out of time on this assignment
+ //and it "just werks"
+ //
+ //I love fighting against my tools to do what I want
+ //"cin" has to be special and have its own little istream type
+ //instead of just being a function that, upon reaching a
+ //terminating character returns a string or a char[].
+ //
+ //but hey, it could be worse, I could be dealing with the
+ //trainwreck that is BOOST
+
+ cout << "===Enter your information===\n";
+ cout << "Please enter your first name: ";
+ cin >> temp;
+ employee.set_fname(temp);
+ cout << "Please enter your last name: ";
+ cin >> temp;
+ employee.set_lname(temp);
+ cout << "Please enter your job title: ";
+ cin >> temp;
+ employee.set_job(temp);
+ cout << "Please enter your employee ID: ";
+ cin >> temp;
+ employee.set_employeeNum(stoi(temp));
+ cout << "Please enter your number of hours worked: ";
+ cin >> temp;
+ employee.set_hrsWorked(stof(temp));
+ cout << "Please enter your wage: ";
+ cin >> temp;
+ employee.set_wage(stof(temp));
+ cout << "Please enter your number of deductions: ";
+ cin >> temp;
+ employee.set_deductions(stoi(temp));
+ return employee;
+}
+
+//given hours work, return the amount of overtime.
+float overtime(Employee employee) {
+ if (employee.get_hrsWorked() > 40) {
+ float oTHours = employee.get_hrsWorked() - 40;
+ if (oTHours > 0) {
+ return oTHours;
+ }
+ }
+ return 0;
+}
+
+//Given the deductions, return the taxrate
+float taxRate(Employee employee) {
+ if (employee.get_deductions() <= 0) {
+ return 0.30;
+ } else if (0.30-(employee.get_deductions()*0.05) <= 0.10) {
+ return 0.10;
+ } else {
+ return 0.30-(employee.get_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.get_wage()*1.5);
+ float normalPay;
+ if (overtime > 0) {
+ normalPay = employee.get_wage()*40;
+ } else {
+ normalPay = employee.get_wage()*employee.get_hrsWorked();
+ }
+ float grossPay = overtimePay + normalPay;
+ float withheld = taxRate*grossPay;
+ cout << "Employee Name: " << employee.get_fname() << " " << employee.get_lname() << endl;
+ cout << "Job Title: " << employee.get_job() << endl;
+ cout << "Employee Number: " << employee.get_employeeNum() << endl;
+ cout << "Hours Worked: " << employee.get_hrsWorked() << endl;
+ cout << "Hourly Wage: $" << employee.get_wage() << endl;
+ cout << "Deductions Claimed: " << employee.get_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
+ const int ARR_SIZE = 3;
+ Employee readValues[ARR_SIZE];
+
+
+ //Collect the data
+ for (int employeePos=0; employeePos < ARR_SIZE; employeePos++) {
+ readValues[employeePos] = serializeIntoObj();
+ }
+ //Present the data
+ for (int employeePos=0; employeePos < ARR_SIZE; employeePos++) {
+ cout << "===New Employee==\n";
+ outputGrossTaxPay(readValues[employeePos], overtime(readValues[employeePos]), taxRate(readValues[employeePos]));
+ }
+
+
+
+
+
+}
+
+/*
+ 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/>.
+ */