summaryrefslogtreecommitdiffstats
path: root/C++/Structs/Structs.cpp
blob: e556264ba638e5c589818e4134193dadf9ef82e7 (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
// 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/>.
   */