Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I already have the code, I just need the User documentation and Flowchart only Thanks #include #include #include #include #include using namespace std; //global constants

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

I already have the code, I just need the User documentation and Flowchart only Thanks

#include #include #include #include #include

using namespace std;

//global constants const char* HEADER = "Chegg "; const char* HEADER_DASHES = "-------------------------------- "; const char* SOCIAL_INSURANCE_NUMBER = "Social insurance no."; const char* NET_PAY = "net pay"; const char* GROSS_PAY = "gross pay"; const char* PENSION = "pension"; const char* DEDUCTIONS = "deductions"; const char* BODY_DASHES = "-------------------------------------------------------------------- "; const char* SUMMARY_HEADER = "Summary "; const char* SUMMARY_DASHES = "------- ";

const char* TOTAL_EMPLOYEES = "Number of employees processed:"; const char* TOTAL_GROSS = "Total gross pay for all employees:"; const char* TOTAL_NET = "Total net pay for all employees:"; const char* TOTAL_PENSION = "Total pension withheld for all employees:"; const char* TOTAL_DEDUCTIONS = "Total deductions for all employees:";

const int REGULAR_WORK_HOUR_LIMIT = 40; //standard weekly regular work hours const int WORK_HOUR_MAX = 54; //max weekly work hours const double PAYRATE_MULTIPLE = 0.5;//the rate applied to the regular payrate

const double TAXABLE_CONSTANT1 = 14.00; const double TAXABLE_CONSTANT2 = 11.00; const double FEDERAL_CONSTANT1 = 0.14; const double FEDERAL_CONSTANT2 = 0.00023; const double PROVINCIAL_CONSTANT1 = 0.35; const double PENSION_CONSTANT1 = 16.50; const double PENSION_CONSTANT2 = 0.077;

const int SIN_MAX_LENGTH = 9; const int exemptionMin = 0; const int exemptionMax = 19; const int hoursWorkedMin = 0; const int hoursWorkedMax = 54; const double payRateMin = 0.00; const double payRateMax = 99.99;

//prototypes bool checkSocialSecurityNumber(long socialInsuranceNum); bool checkExemptions(int numberOfExemptions); bool checkHoursWorked(double hoursWorked); bool checkPayRate(double payRate);

double calculateGrossPay(double payRate, double hoursWorked); double calculateFederalAndProvincialDeduction(double grossPay, int numberOfExemptions); double calculatePension(double grossPay); double calculateNetPay(double grossPay, double deductions, double pension);

// One way to specify a file name: const char * IN_FILE = "input.txt";

// A second way to specify a file name: #define OUT_FILE "output.txt"

int main() { //Declare variables long socialInsuranceNum; // social security number of employee int numberOfExemptions; // store number of excemptions for employee

double payRate = 0.0, // store the pay rate for the employee hoursWorked = 0.0, // store hours worked for the employee grossPay = 0.0, // store gross pay for the employee netPay = 0.0, // store netpay for the employee pension = 0.0, // store pension for the employee deductions = 0.0, // store deductions for the employee totalGrossPay = 0.0, // total gross pay of all employees totalNetPay = 0.0, // total net pay for all all employees totalPension = 0.0, // total pension pay for all employees totalDeductions = 0.0; // total deductions for all employees

//Define ifstream object and open file ifstream ins; ins.open(IN_FILE);

//Check that file opened without any issues if (ins.fail()) { cerr Unable to open input file : "

//Define ofstream object and open file ofstream outs; outs.open(OUT_FILE);

//Check that file opened without any issues if (outs.fail()) { cerr Unable to open output file : "

outs

outs

outs

outs

int employeeCounter = 0; //store employee counter, increments by one every time a valid data set is found

while (!ins.eof()) { ins >> socialInsuranceNum >> payRate >> numberOfExemptions >> hoursWorked; bool validNumber = checkSocialSecurityNumber(socialInsuranceNum); bool validExemptions = checkExemptions(numberOfExemptions); bool validHoursWorked = checkHoursWorked(hoursWorked); bool validPayRate = checkPayRate(payRate);

if (validNumber && validExemptions && validHoursWorked && validPayRate) { employeeCounter++;

grossPay = calculateGrossPay(payRate, hoursWorked); totalGrossPay += grossPay;

deductions = calculateFederalAndProvincialDeduction(grossPay, numberOfExemptions); totalDeductions += deductions;

pension = calculatePension(grossPay); totalPension += pension;

netPay = calculateNetPay(grossPay, deductions, pension);//deduction and pension has to be calculated first to get net pay totalNetPay += netPay;

outs

if (!validPayRate) { cerr

if (!validExemptions) { cerr

if (!validHoursWorked) { cerr

outs

outs

outs

// Close files ins.close(); outs.close();

_getch(); // causes execution to pause until char is entered }

//Fuction to check if the social insurance number is a 9 digit number bool checkSocialSecurityNumber(long socialInsuranceNum) { bool validInput; string sin = to_string(socialInsuranceNum);

while (sin.length() == SIN_MAX_LENGTH && sin.at(0) != 0) { return true; }

return false; }

//Function to check if number of exemptions is between 0 to 19 bool checkExemptions(int numberOfExemptions) { bool validInput;

while (numberOfExemptions >= exemptionMin && numberOfExemptions

return false; }

//Function to check number of hours worked bool checkHoursWorked(double hoursWorked) { bool validInput;

while (hoursWorked >= hoursWorkedMin && hoursWorked

return false; }

//Function to check if hourly pay rate is between 0 to 99.99 - and no negative numbers bool checkPayRate(double payRate) { bool validInput;

while (payRate >= payRateMin && payRate

return false; }

//Function to calculate Gross Pay - Regular pay for the first 40 hours and //time and a half beyond that, up to a limit of 54 hours in any given week. double calculateGrossPay(double payRate, double hoursWorked) {

double grossPayAmount = 0;

if (hoursWorked

if (hoursWorked

//Function to calculate Deductions - Let "gross" represent gross pay and "taxable" represent taxable pay.

double calculateFederalAndProvincialDeduction(double grossPay, int numberOfExemptions) {

double taxable = 0; double federal = 0; double provincial = 0; double totalDeduction = 0; //federal + provincial

taxable = grossPay - (TAXABLE_CONSTANT1 * numberOfExemptions) - TAXABLE_CONSTANT2; //calculate taxable salary

if (taxable >= 0) { //check if taxable pay is not negative federal = taxable * (FEDERAL_CONSTANT1 + (FEDERAL_CONSTANT2 * taxable)); provincial = federal * PROVINCIAL_CONSTANT1; //defined as 35 % of the amount withheld for federal income tax totalDeduction = federal + provincial; return totalDeduction; }

return totalDeduction; //if taxable is less than 0 then just return 0 }

//Function to calculate pension pay double calculatePension(double grossPay) {

double pension = 0;

pension = grossPay * PENSION_CONSTANT2;

if (pension > PENSION_CONSTANT1) { return PENSION_CONSTANT1;//$16.50 or 7.7% of gross, whichever is less. }

return pension; }

//Net pay - Gross pay less all deductions. double calculateNetPay(double grossPay, double deductions, double pension) {

double netPay = 0;

if (grossPay >= (deductions - pension)) { //makes sure gross pay is larger than deductions netPay = grossPay - deductions - pension; return netPay; }

return 0; //if deductions exceed net pay then just return 0 for net pay }

You should use the following input data from a file. You have to create a file using the note pad and type in the following information, The first column is the social insurance number, the second column is pay rate, the third column is number of exemptions and the fourth column is hours worked. Social insurance number: a 9 digit number (long int should be used) Pay rate: a decimal number (use float data type) Number of exemptions: a whole number (use int data type) Hours worked: a decimal number (use float data type) 123456789 234567812 234512345 123456799 213456782 123452345 123456321 213345657 123533212 423556578 555555125 293049506 938950677 766445667 432123567 25.5 15.5 16.3 15.5 25.5 17.5 -10.5 10.5 17.2 19.5 30.0 15.0 0.0 25.5 20.5 40.0 45.0 60.0 40.0 50.5 35.0 24.5 45.0 -25.0 65.0 35.5 0.0 0.0 40.0 25.5 3 4 3 2 3 20 3 10 You should do input data checks. If the input data is negative an error message should be printed Number of exemptions should be from 0 to 19

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions

Question

Why isnt choosing a legal entity a onetime event?

Answered: 1 week ago

Question

Discuss the techniques of sales forecasting.

Answered: 1 week ago

Question

Write short notes on Marketing mix.

Answered: 1 week ago