From 9d53d8857eaa1c9405894a88ca75bc4657e42f35 Mon Sep 17 00:00:00 2001 From: msglm Date: Sat, 14 Jan 2023 05:31:48 -0600 Subject: Inital Commit --- C++/OOP/OOP.cpp | 205 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 C++/OOP/OOP.cpp (limited to 'C++/OOP/OOP.cpp') 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 +#include +#include +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 . + */ -- cgit v1.2.3