Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // James Gallagher
- // Cs 215 Section 010
- // Project 2: Payroll
- //Description: This program is deisnged to recieve and process information about a companies payroll and print a comprehensive report
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- //-----Print:Logo-----
- void PrintLogo()
- {
- cout << "+---------------------------------+" << "\n"
- << "| James Gallagher's Propane |" << "\n"
- << "| and Propane accessories |" << "\n"
- << "| Kevin Joiner Sec 10 |" << "\n"
- << "+---------------------------------+";
- }
- //-----Ask:Num-----
- float asknumemployees(float & num_emplyees)
- {
- do {
- cout << "\n" << "Number of empoyees: ";
- cin >> num_emplyees;
- if (num_emplyees < 1)
- {
- cout << "Invalid: Enter a number greater than 1";
- }
- } while (num_emplyees < 1);
- return num_emplyees;
- }
- //-----Ask:Resident-----
- string AskResident(string& employee_resident)
- {
- do {
- cout << " Local Resident (Y/N)?: ";
- cin >> employee_resident;
- if (employee_resident == "Y" || employee_resident == "y" || employee_resident == "N" || employee_resident == "n")
- {
- return employee_resident;
- }
- else
- {
- cout << "Invalid: Please enter (Y/N)" << "\n";
- }
- } while (employee_resident != "Y" && employee_resident != "y" && employee_resident != "N" && employee_resident != "n");
- }
- //-----Ask:type-----
- string Askemployee_type(string& employee_type)
- {
- do {
- cout << " Hourly or Salaried (H/S)?: ";
- cin >> employee_type;
- if (employee_type == "H" || employee_type == "h" || employee_type == "S" || employee_type == "s")
- {
- return employee_type;
- }
- else
- {
- cout << "INVALID: Enter H or S";
- }
- } while (employee_type != "H" && employee_type != "h" && employee_type != "S" && employee_type != "s");
- }
- //-----Calc:State-----
- float CalcStateTax(float gross_pay)
- {
- float state_tax_total = 0;
- const float state_income_tax = .06;
- if (gross_pay > 500)
- {
- state_tax_total = gross_pay - 500;
- state_tax_total = gross_pay * state_income_tax;
- }
- return state_tax_total;
- }
- //-----Calc:Local-----
- float CalcLocalTax(float gross_pay, string employee_resident)
- {
- float local_tax_total = 0;
- if ((employee_resident == "y") || (employee_resident == "Y"))
- {
- local_tax_total = gross_pay * 0.015;
- }
- if ((employee_resident == "n") || (employee_resident == "N"))
- {
- local_tax_total = gross_pay * 0.01;
- }
- return local_tax_total;
- }
- //-----Calc:Fed-----
- float calcFedTax(float gross_pay)
- {
- float fed_tax_total = 0;
- if (gross_pay < 600) {
- fed_tax_total = 0;
- }
- else if ((gross_pay <= 799.99) && (gross_pay >= 600)) {
- fed_tax_total = gross_pay * 0.04;
- }
- else if ((gross_pay <= 1099.99) && (gross_pay >= 800)) {
- fed_tax_total = gross_pay * 0.08;
- }
- else {
- fed_tax_total = gross_pay * 0.12;
- }
- return fed_tax_total;
- }
- //-----Hourly-----
- float GetHourlyGross(float hourly_rate, float hours_worked)
- {
- float overtime = 40;
- float hourlyGross = 0;
- if (hours_worked <= 40)
- {
- hourlyGross = hourly_rate * hours_worked;
- }
- if (hours_worked > 40)
- {
- hourlyGross = (40 + ((hours_worked - 40) * 1.5)) * hourly_rate;
- }
- return hourlyGross;
- }
- //-----Update-----
- float updateTotals(float net_total, float fed_tax_total, float state_tax_total, float local_tax_total, float social_sec_tax, float & Final_social_sec, float & Final_fed_tax, float & Final_local_tax, float & Final_state_tax, float & Final_net_due)
- {
- Final_fed_tax = Final_fed_tax + fed_tax_total;
- Final_net_due = Final_net_due + net_total;
- Final_state_tax = Final_state_tax + state_tax_total;
- Final_local_tax = Final_local_tax + local_tax_total;
- Final_social_sec = Final_social_sec + social_sec_tax;
- return Final_social_sec;
- }
- //-----Print:Stub-----
- void printstub(string first_name, string last_name, float gross_pay, float fed_tax_total, float state_tax_total, float local_tax_total, float social_sec_tax, float totaltaxes, float net_total)
- {
- cout << "\n" << "--------James Gallagher's Company Paystub--------" << "\n";
- cout << setprecision(2) << "Name: " << first_name << " " << last_name << "\n";
- cout << setprecision(2) << fixed << "Gross Pay: $" << gross_pay << "\n";
- cout << setprecision(2) << "Federal Tax: $" << fed_tax_total << "\n";
- cout << setprecision(2) << "State Tax: $" << state_tax_total << "\n";
- cout << setprecision(2) << "Local Tax: $" << local_tax_total << "\n";
- cout << setprecision(2) << "Socail Security Tax: $" << social_sec_tax << "\n";
- cout << setprecision(2) << "Total Taxes: $" << totaltaxes << "\n";
- cout << setprecision(2) << fixed << "Net Total: $" << net_total << "\n";
- }
- //-----PRint:Report-----
- void PrintReport(float Final_social_sec, float Final_fed_tax, float Final_local_tax, float Final_state_tax, float Final_net_due)
- {
- cout << "--------------PAYROLL REPORT--------------" << "\n";
- cout << "Total pay to Employees : " << Final_net_due << "\n";
- cout << "Total pay to Federals : " << Final_fed_tax << "\n";
- cout << "Total pay to SSI : " << Final_social_sec << "\n";
- cout << "Total pay to State : " << Final_state_tax << "\n";
- cout << "Total pay to Local : " << Final_local_tax << "\n";
- cout << "------------------------------------------" << "\n";
- }
- //-----PROCESS-----
- void ProcessEmployee(int num_employees, float & Final_social_sec, float & Final_fed_tax, float & Final_local_tax, float & Final_state_tax, float & Final_net_due)
- {
- string first_name, last_name, employee_type, employee_resident;
- float counter = 0, hourly_rate = 0, hours_worked = 0, weeklySalary = 0, hourlyGross = 0, gross_pay = 0, fed_tax_total = 0, local_tax_total = 0, state_tax_total = 0, social_sec_tax = 0, totalTaxes = 0, net_total = 0, employeeStateTotal = 0, employee_net_total = 0, employee_fed_total = 0, employee_local_total = 0, employeeSSITotal = 0;
- for (counter; counter < num_employees; counter++)
- {
- cout << "----------------------------" << "\n";
- cout << " Enter Data for Employee " << setprecision(0) << counter + 1 << "\n";
- cout << " Name (first last): ";
- cin >> first_name >> last_name;
- Askemployee_type(employee_type);
- if (employee_type == "H" || employee_type == "h")
- {
- cout << " Hourly rate: ";
- cin >> hourly_rate;
- cout << " Hours worked this period: ";
- cin >> hours_worked;
- }
- if (employee_type == "S" || employee_type == "s")
- {
- cout << " Weekly Salary: ";
- cin >> weeklySalary;
- }
- AskResident(employee_resident);
- if (employee_type == "H" || employee_type == "h")
- {
- hourlyGross = GetHourlyGross(hourly_rate, hours_worked);
- gross_pay = hourlyGross + 0;
- }
- if (employee_type == "S" || employee_type == "s")
- {
- gross_pay = weeklySalary + 0;
- }
- fed_tax_total = calcFedTax(gross_pay);
- local_tax_total = CalcLocalTax(gross_pay, employee_resident);
- state_tax_total = CalcStateTax(gross_pay);
- social_sec_tax = gross_pay * 0.03;
- totalTaxes = fed_tax_total + state_tax_total + local_tax_total + social_sec_tax;
- net_total = gross_pay - totalTaxes;
- printstub(first_name, last_name, gross_pay, fed_tax_total, state_tax_total, local_tax_total, social_sec_tax, totalTaxes, net_total);
- Final_social_sec = updateTotals(net_total, fed_tax_total, state_tax_total, local_tax_total, social_sec_tax, Final_social_sec, Final_fed_tax, Final_local_tax, Final_state_tax, Final_net_due);
- Final_fed_tax = updateTotals(net_total, fed_tax_total, state_tax_total, local_tax_total, social_sec_tax, Final_social_sec, Final_fed_tax, Final_local_tax, Final_state_tax, Final_net_due);
- Final_local_tax = updateTotals(net_total, fed_tax_total, state_tax_total, local_tax_total, social_sec_tax, Final_social_sec, Final_fed_tax, Final_local_tax, Final_state_tax, Final_net_due);
- Final_state_tax = updateTotals(net_total, fed_tax_total, state_tax_total, local_tax_total, social_sec_tax, Final_social_sec, Final_fed_tax, Final_local_tax, Final_state_tax, Final_net_due);
- Final_net_due = updateTotals(net_total, fed_tax_total, state_tax_total, local_tax_total, social_sec_tax, Final_social_sec, Final_fed_tax, Final_local_tax, Final_state_tax, Final_net_due);
- }
- cout << "\n";
- PrintReport(employeeStateTotal, employee_net_total, employee_fed_total, employee_local_total, employeeSSITotal);
- counter = counter + 1;
- }
- //-----MAIN-----
- void main()
- {
- float num_employees = 0;
- const float State_income_tax = .06;
- const float social_sec_tax = .03;
- float Final_social_sec = 0;
- float Final_fed_tax = 0;
- float Final_local_tax = 0;
- float Final_state_tax = 0;
- float Final_net_due = 0;
- PrintLogo();
- num_employees = asknumemployees(num_employees);
- ProcessEmployee(num_employees, Final_social_sec, Final_fed_tax, Final_local_tax, Final_state_tax, Final_net_due);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement