summaryrefslogtreecommitdiffstats
path: root/C++/Final/Final Program.cpp
blob: e257f12ca6275ee7a6072b75ab4a7988ab3edd83 (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
// Name: msglm
// Date: 4/29/2022
// Title: Payroll Calculator
// Description: Takes input data from file deliminated by a space. This information is then used to calculate taxes, net, and gross pay for each person in the entry.

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

// Named constants
int ARRAY_SIZE = 10;
double FED_TAX=0.09;
double STATE_TAX=0.05;
double FICA_TAX=0.062;


// Function prototype
double GrossPay(double x, double y);
double Tax(double x);

// Main function--------------------------------------------------------------
int main()
{
	// Declare Varibles
	string lName[ARRAY_SIZE];
	string fName[ARRAY_SIZE];
	string fullName;
	double payrate[ARRAY_SIZE];
	double hours[ARRAY_SIZE];
	double grossPay[ARRAY_SIZE];
	double netPay[ARRAY_SIZE];
	double taxesOwed[ARRAY_SIZE];
        double totalGrossPay;
        double totalTaxes;
        double totalNetPay;

	// Declare variables for files
	ifstream inputFile;
	ofstream outputFile;

	// Open files
	inputFile.open("hourlyinput.txt");
	outputFile.open("hourlyoutput.txt");




	// Print grogram title and description
	cout << "Title: Payroll Calculator" << endl << "Description: Takes input data from file deliminated by a space. This information is then used to calculate taxes, net, and gross pay for each person in the entry." << endl;


	// check to make sure input file opened
	if (inputFile) {
		cout << "Successfully opened file";
	} else {
		cout << "ERROR! File failed to open!";
			return 1;
	}

	// Collect data from the file (Parallel Arrays)

	for (int i = 0; i < ARRAY_SIZE; i++) {
		inputFile >> fName[i] >> lName[i] >> payrate[i] >> hours[i];


	// Calculate Gross pay for all employees and store in arrays
		grossPay[i] = GrossPay(hours[i], payrate[i]);


	// Calculate taxes for all employees and store in arrays
	
		taxesOwed[i] = Tax(grossPay[i]);
	
	

	// Calculate net pay for each employee and store in arrays
	
		netPay[i] = grossPay[i] - taxesOwed[i];
	}

	// Printing payroll report to an OUTPUT FILE
	
	outputFile << fixed << left << showpoint << setprecision(2);
	outputFile << setw(17) << "Name" << setw(13) << "Payrate" << setw(9) << "Hours" << setw(9) << "Gross" << setw(9) << "Taxes" << setw(9) << "Net" << endl;
	for (int i = 0; i < ARRAY_SIZE; i++) {
	fullName = fName[i] + " " + lName[i]; 
	outputFile << setw(17) << fullName << setw(13) << payrate[i] << setw(9) << hours[i] << setw(9) << grossPay[i] << setw(9) << taxesOwed[i] << setw(9) << netPay[i] << endl;
	}
	
	cout << "Outputted to file.";

	// Print payroll statistics to the SCREEN
	
	for (int i = 0; i < ARRAY_SIZE; i++)
            {
                totalGrossPay = totalGrossPay + grossPay[i];
                totalTaxes = totalTaxes + taxesOwed[i];
                totalNetPay = totalNetPay + netPay[i];
            }
	cout << "Weekly Payroll Statistics:\n\n" ;
	cout << "Total Gross Pay: " << totalGrossPay << endl;
	cout << "Total Taxes: " << totalTaxes << endl; 
	cout << "Total Net Pay: " << totalNetPay << endl;



	// Close files
	outputFile.close();
	inputFile.close();


	return 0;
}

// Function definations

double GrossPay(double payRateValue, double hours)
{

return payRateValue*hours;

}

double Tax(double grossPayValue)
{
	double FICAOwed = grossPayValue * FICA_TAX;
	double stateOwed = grossPayValue * STATE_TAX;
	double fedOwed = grossPayValue * FED_TAX;
	double totalTax = FICAOwed + stateOwed + fedOwed;
	return totalTax;
}