Question
***** CODING IN C++ ***** Overview For this assignment, write a program that uses function to calculate the weekly payment amount for an employee of
***** CODING IN C++ *****
Overview
For this assignment, write a program that uses function to calculate the weekly payment amount for an employee of Purple Prose Press.
The employee's weekly payment amount is based on:
- The number of hours worked - (minimum: 0, maximum: 60)
- The hourly wage - (minimum: $0.00, maximum: $30.00)
- The number of exemptions - (minimum: 0, maximum: 5)
The three values will be used to calculate:
- Gross payment amount
- Federal income tax withheld
- State income tax withheld
- Social Security withheld
- Net pay amount
Basic Logic for int main()
Declare any variables that are needed.
Call the validInt function that is described below to get the number of hours the employee worked. The value must be between 0 and 60 as mentioned above. Make sure to save the value that is returned from the validInt function in an integer variable.
Call the validDouble function that is described below to get the hourly wage for the employee. The value must be between 0.00 and 30.00 as mentioned above. Make sure to save the value that is returned from the validDouble function in a double variable.
Call the validInt function that is described below to get the number of exemptions the employee claimed. The value must be between 0 and 5 as mentioned above. Make sure to save the value that is returned from the validInt function in an integer variable.
Call the grossPay function that is described below to calculate the employee's gross payment amount. Make sure to pass the hourly wage for the employee (the double value returned from the validDouble call) and the number of hours the employee worked (the integer value returned from the first validInt call) to the grossPay function. The value that is returned from the grossPay function should be saved in a double variable.
Call the federalTax function that is described below to calculate the amount of federal income tax that is withheld from the employee. Make sure to pass the employee's gross payment amount (the double value returned from the grossPay call) and the number of exemptions the employee claimed (the integer value returned from the second validInt call) to the federalTax function. The value that is returned from the federalTax function should be saved in a double variable.
Call the stateTax function that is described below to calculate the amount of state income tax that is withheld from the employee. Make sure to pass the employee's gross payment amount (the double value returned from the grossPay call) and the number of exemptions the employee claimed (the integer value returned from the second validInt call) to the stateTax function. The value that is returned from the stateTax function should be saved in a double variable.
Call the socialSecurity function that is described below to calculate the amount of social security that is withheld from the employee. Make sure to pass the employee's gross payment amount (the double value returned from the grossPay call) to the socialSecurity function. The value that is returned from the socialSecurity function should be saved in a double variable.
Call the netPay function that is described below to calculate the employee's net payment amount. Make sure to pass the employee's gross payment amount (the double value returned from the grossPay call), the amount of federal income tax that is withheld from the employee (the double value returned from the federalTax call), the amount of state income tax that is withheld from the employee (the double value returned from the stateTax call), and the amount of social security that is withheld from the employee (the double value returned from the socialSecurity call) to the netPay function. The value that is returned from the netPay function should be saved in a double variable.
Display the number of hours the employee worked, the hourly wage for the employee, the employee's gross payment amount, the amount of federal income tax that is withheld from the employee, the amount of state income tax that is withheld from the employee, the amount of social security that is withheld from the employee, and the employee's net payment amount. The dollar amounts should have exactly two digits after the decimal point, including zeros. The decimal points of the dollar amounts should line up as shown in the Output section.
The Functions
Write and use the following 7 functions in the program.
int validInt( string prompt, int lower_bound, int upper_bound )
This function gets an integer value from the user that is within a specific range. It takes three arguments: a string that is used as a prompt to the user to indicate what should be entered, an integer that represents the smallest integer value that can be entered, and an integer that represents the largest integer value that can be entered. It returns an integer: the integer value that is within the specific range.
The function should display the string argument and the two integer values to the user and then get the user's value. A loop should be used to verify the user's value. As long as the user enters a value that is not within the specified range, an error message should be displayed and the user should be given a chance to re-enter the value. Once the user enters a valid value, it should be returned to the caller.
As an example of how this function might be used - in previous programs, to get an integer value from the user that is between 10 and 99, there might have been something like:
cout << "Enter a 2 digit number (10...99): "; cin >> num;
In this program, the above cout/cin statement should be replaced with:
num = validInt( "Enter a 2 digit number", 10, 99 );
which should produce a prompt similar to:
Enter a 2 digit number (10...99):
The actual format of how the prompt and specific range are specified is left up to you, but the display MUST include the range of values.
double validDouble( string prompt, double lower_bound, double upper_bound )
This function is like validInt, except that it works with double values rather than integer values.
double grossPay( double wage, int hours_worked )
This function calculates and returns an employees gross payment amount for one week. It takes two arguments: a double that represents the employees hourly wage and an integer that represents the number of hours that the employee worked for one week. It returns a double: the calculated gross payment amount.
The maximum number of hours that an employee can work before they start to earn overtime pay is 40 hours. If the number of hours worked is less than or equal to 40, the gross payment amount is equal to the hourly wage times the number of hours worked. If the number of hours worked is greater than 40, the gross payment amount is equal to 40 times the hourly wage plus 1.5 times the hourly wage for every hour over 40.
double federalTax( double gross_pay, int num_exemptions )
This function calculates and returns the amount of federal income tax to withhold from an employee. It takes two arguments: a double that represents the employees gross payment amount and an integer argument that represents the number of exemptions claimed by the employee. It returns a double: the amount of federal tax to withhold.
The federal withholding allowance for a weekly pay period is $55.77. The amount of the employees gross pay that is subject to federal taxation is equal to the employee's gross payment amount minus (the federal withholding allowance times the number of exemptions). The amount subject to taxation is then used to calculate the federal income tax to withhold. The amount to withhold can be calculated using the following table:
Amount subject to taxation(X) Amount to withhold X < $51 $0 $51 < X < $552 15% of X $552 < X < $1196 $75.15 plus 28% of X greater than $552 $1196 < X < $2662 $255.47 plus 31% of X greater than $1196 $2662 < X < $5750 $709.93 plus 36% of X greater than $2662 $5750 < X $1821.61 plus 39.6% of X greater than $5750
If an employees gross pay is $1600.00 and they have 2 exemptions, the amount of federal income tax withheld is $346.13.
Amount subject to taxation = 1600.00 - (55.77 * 2) = 1488.46
31% of amt sub. to taxation > $1196 = 0.31 * (1488.46 - 1196) = 90.66
Amount to withhold = 255.47 + 90.66 = 346.13
double stateTax( double gross_pay, int num_exemptions )
This function calculates and returns the amount of state income tax to withhold from an employee. It takes two arguments: a double that represents the employees gross payment amount and an integer that represents the number of exemptions claimed by the employee. It returns a double: the amount of state income tax to withold.
The state exemption amount for a weekly pay period is $38.46. If the employees gross payment amount is less than or equal to the state exemption amount times the number of exemptions, the amount of the state income tax to withhold is $0.00. If the employees gross payment amount is greater than the state exemption amount times the number of exemptions, the amount of state income tax to withhold is equal to 3% of (gross pay minus (the state exemption amount times the number of exemptions)).
double socialSecurity( double gross_pay )
This function calculates and returns the amount of social security to withhold from an employee. It takes one argument: a double that represents the employees gross payment amount. It returns a double: the calculated amount of social security to withhold from an employee.
The amount of social security to withhold from the employee is equal to 7.65% of the employees gross payment amount.
double netPay( double gross_pay, double federal_withhold, double state_withhold, double social_security )
This function calculates and returns the employee's net payment amount. It takes four arguments: a double that represents the gross payment amount, a double that represents the amount of federal tax that is withheld, a double that represents the amount of state tax that is withheld, and a double that represents the amount of social security that is withheld. It returns a double: the calculated net payment amount.
The net payment amount is equal to the gross payment amount minus the sum of the amount of federal tax that is withheld, the amount of state tax that is withheld, and the amound of social security that is withheld.
Symbolic Constants
The program must use at least three symbolic constants.
The constants should represent the federal withholding allowance ($55.77), the state exemption amount ($38.46), and the social security percentage (7.65%). Note: keep in mind that the social security constant is a percentage. The value that is assigned to the constant will determine how the constant is used in the socialSecurity function when calculating the amount of social security to withhold.
There may be more symbolic constants if needed.
Programming Requirements
-
As with the previous assignments and the assignments until the end of the semester, complete program documentation is required. For this assignment, that means that line documentation AND function documentation boxes are needed. Make sure that main() and any function that is written contains line documentation.
Each function must have a documentation box detailing:
- its name
- its use or purpose: that is, what does it do? What service does it provide to the code that calls it?
- a list of its arguments briefly describing the meaning and use of each
- the value returned (if any) or none
- notes on any unusual features, assumptions, techniques, etc.
/*************************************************************** Function: double validDouble( string prompt, double lower_bound, double upper_bound ) Use: This function gets a double value within a specified range Arguments: prompt - a string that represents a prompt to the user to let them know what type of information to enter lower_bound - a double that represents the lower bound of the specified range upper_bound - a double that represents the upper bound of the specified range Returns: A double that is within the specified range Note: None ***************************************************************/
-
As mentioned above, use the validInt function to get the number of hours worked and the number of exemptions from the user. Use the validDouble function to get the hourly wage amount from the user.
-
Hand in a copy of the source code (CPP file) using Blackboard.
-
Output
Run 1
Enter the number of hours worked (0...60): -8 The value must be between (0...60). Try again: 65 The value must be between (0...60). Try again: 60 Enter the hourly wage (0.00...30.00): -5 The value must be between (0.00...30.00). Try again: 45 The value must be between (0.00...30.00). Try again: 30 Enter the number of exemptions (0...5): -9 The value must be between (0...5). Try again: 7 The value must be between (0...5). Try again: 2 You worked 60 hours at $30.00 per hour. Gross Pay 2100.00 Federal Tax 501.13 State Tax 60.69 Social Security 160.65 Net Pay 1377.53
Run 2
Enter the number of hours worked (0...60): 32 Enter the hourly wage (0.00...30.00): 14.25 Enter the number of exemptions (0...5): 0 You worked 32 hours at $14.25 per hour. Gross Pay 456.00 Federal Tax 68.40 State Tax 13.68 Social Security 34.88 Net Pay 339.04
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started