// 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 #include #include #include 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; }