summaryrefslogtreecommitdiffstats
path: root/C++/OOP/OOP.cpp
blob: 76d5735a5502ef6d13dbe5308bd0df78650bde18 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
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/>.
   */