Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program that calculates weekly pay for an employee of CDE, i nc. . T

ID: 3680159 • Letter: W

Question

Write a C++ program that calculates weekly pay for an employee of CDE, inc.. The program will run as long as the user enters ‘y’ or ‘Y’ when asked if they want to calculate weekly pay.

The program should first ask the user if they want to calculate their pay amount for a week. If the user enters ‘y’ or ‘Y’, it should ask the user for three values:

The number of hours worked - (min: 0, max: 60)
The hourly wage - (min: $0.00, max: $30.00)
The number of exemptions - (min: 0, max: 5)
Those three values will then be used to calculate:

Gross pay
Net pay
Social Security
Federal income tax
State income tax

The Net pay forumula is:
Net pay = Gross pay - (Social security + Federal income tax + State income tax)

Once the user doesn't want to calculate weekly pay, print the total gross pay, total net pay, and a series of asterisks equal to the number of weeks that weekly pay has been calculated for. The total values should only display if the user calculated one or more weeks worth of pay.

Functions required:

double CalculateGrossPay( double wage, int hoursWorked )

The function should calculate and return an employee’s gross pay for a week. It takes two inputs: a double representing the employee’s hourly wage and an integer for the number of hours that the employee worked in one week.

The max number of hours that an employee can work before they start to earn overtime pay is 40 hours. If the hours worked is less than or equal to 40, gross pay is equal to the hourly wage times the number of hours worked. If the number of hours worked is greater than 40, gross pay is equal to 40 times the hourly wage + 1.5 times the hourly wage for every hour over 40.

double CalculateFederalTax( double grossPay, int numExemptions )

This function calculates and returns the federal tax to withhold from an employee. It takes two inputs: a double for the employee’s gross pay and an integer that represents the number of exemptions claimed by the employee.

The federal withholding allowance for a weekly pay period is $55.77. The amount of the employee’s gross pay that is subject to federal taxation is equal to gross pay - (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 employee’s gross pay is $1600.00 & they have 2 exemptions, the 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 CalculateStateTax( double grossPay, int numExemptions )

This function calculates and returns the state income tax to withhold from an employee. It takes two inputs: a double that represents the employee’s gross pay and an integer for the number of exemptions claimed by the employee.

The state exemption amount for a weekly pay period is $38.46. If the employee’s gross pay 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 employee’s gross pay 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 CalculateSocialSecurity( double grossPay )

This function calculates and returns the amount of social security to withhold from an employee. It takes one argument: a double that represents the employee’s gross pay.

The amount of social security to withhold from the employee is equal to 7.65% of the employee’s gross pay.

int ValidInt( string prompt, int lowerBound, int upperBound )

This function gets an integer from the user that is within a certain range. It takes three arguments: a string that is used as a prompt to the user to tell them what number they are entering, an integer that represents the smallest integer that the user can enter, and an integer that represents the largest integer that the user can enter.

The second and third arguments will be used to ensure that the user enters a valid value. If an invalid value is entered, display an error message and prompt the user to re-enter a value. This should be done repeatedly until the user enters a valid integer. The function returns the valid integer.

A calling statement like: num = ValidInt( "Enter a 2 digit number", 10, 99 );

Should produce the following prompt: Enter a 2 digit number (10...99):

double ValidDouble( string prompt, double lowerBound, double upperBound )

This function is just like ValidInt, except that it takes two doubles, instead of integers.

void BarGraph( int numWeeks )

The purpose of this function is to display a line of asterisks equal to the number of weeks that weekly pay has been calculated. It takes one argument: an integer that represents the number of weekly pay calculations that have been performed. This function returns nothing.

Programming Requirements:

Define symbolic constants for the federal withholding allowance ($55.77), the state exemption amount ($38.46), and the social security percentage (7.65%). You may use more symbolic constants if you desire, but you must have at least the three listed 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.

The program should run as long the user enters ‘y’ or ‘Y’. Use one of the "to" functions to avoid having to code a compound condition.

Display the week number before displaying the gross pay, taxes, social security, and net pay. (see sample output)

Your program must be fully documented. There must be a documentation box for every function in the program. Line documentation should be used wherever needed, but need not be on every line of code. White space and indentation should be used to make your code easily readable.

Hand in a copy of your source code using Blackboard.

Sample Output:

Would you like to calculate your weekly pay? Y

Enter the number of hours worked (0...60): 60
Enter the hourly wage (0.00...30.00): 30.00
Enter the number of exemptions (0...5): 2

Week 1:
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.52


Would you like to calculate your weekly pay? n

Total Gross Pay: 2100.00
Total Net Pay: 1377.52

Total Number of Weeks: *

Explanation / Answer


    #include <iostream>
    #include <iomanip>
    #include <math.h>
    using namespace std;
    #define FEDERAL_WITHHOLDING 55.77
    #define STATE_EXEMPTION     38.46
    #define SOCIAL_SECURITY     .0765
    // Setting up all prototypes for the functions
    double CalculateGrossPay( double, int );
    double CalculateFederalTax( double, int );
    double CalculateStateTax( double, int );
    double CalculateSocialSecurity( double );
    int ValidInt( string, int , int );
    double ValidDouble( string, double, double );
    void BarGraph( int );
    int WeekDisplay ( int );
    int main()
    {
    // Declaring all variables
    char yesOrNo;
    int hoursWorked,numExemptions,numWeeks=0, numWeekDisplay=1;
    double wage,grossPay,federalTax,stateTax,sstate,netPay,totalGross=0,totalNet=0;
    //Setting the precision
    cout<<setprecision(2)<<fixed<<showpoint;
    // Asking the user whether they want to calculate their weekly pay
    cout << "Do you want to calculate your weekly pay? (Y/N) ";
    cin >> yesOrNo;
    // Setting up a while statement for when the user enters 'y' or 'Y'
    while( yesOrNo == 'y' || yesOrNo == 'Y' )
       {
       // Setting up calling statements
       hoursWorked = ValidInt(" Enter the number of hours worked - (minimum: 0, maximum: 60) ",0,60);
       wage = ValidDouble("Enter the hourly wage - (minimum: $0.00, maximum: $30.00) ",0.,30.);
       numExemptions = ValidInt("Enter the number of exemptions - (minimum: 0, maximum: 5) ",0,5);
     
       // Setting variables equal to the functions to be executed
       grossPay = CalculateGrossPay( wage, hoursWorked );
       federalTax = CalculateFederalTax( grossPay, numExemptions );
       stateTax = CalculateStateTax( grossPay, numExemptions );
       sstate = CalculateSocialSecurity( grossPay );
       netPay = grossPay - ( sstate + federalTax + stateTax );
       numWeekDisplay = WeekDisplay ( numWeekDisplay);
     
     
       // Displaying the results
       cout << " Week " << numWeekDisplay << ":" << endl;
       cout << "You worked " << hoursWorked << " hours at $" << wage << " per hour. ";
       cout << "Gross Pay:           " << grossPay << endl;
       cout << "Federal Tax:         " << federalTax << endl;
       cout << "State Tax:           " << stateTax << endl;
       cout << "Social Security:     " << sstate << endl;
       cout << "Net Pay:             " << netPay << endl;
      
       totalGross+=grossPay;         // total gross pay = gross pay + total gross pay
       totalNet+=netPay;             // total net pay = net pay + total net pay
       numWeeks++;                   // increase # of weeks every time user wants to calculate weekly pay
       numWeekDisplay++;
     
       // Ask the user whether they want to calculate weekly pay again
       cout << " Do you want to calculate your weekly pay? (Y/N) ";
       cin >> yesOrNo;
       }
    // If the user enters no, display this at the end
    cout << " Total Gross Pay:     " << totalGross << endl;
    cout << "Total Net Pay:       " << totalNet << endl;
    BarGraph( numWeeks );
    cout << endl;
    system ("pause");
    return 0;
    }
    // Setting up all functions
    /*****************************************************************************
    double CalculateGrossPay( )
    The purpose of this function is to calculate and return an employee's gross
    pay for one week. It takes two arguments: a double representing the employee's
    hourly wage and an integer representing the number of hours that the employee
    worked for one week.
    *****************************************************************************/
    double CalculateGrossPay( double wage, int hoursWorked )
    {
    //Declaring variables
    double grossPay;
    // Setting up if-else statement
    if( hoursWorked > 40)
      {
      // formula to be used if hours worked is over 40
      grossPay = ( wage * 40) + ( wage * 1.5 * (hoursWorked - 40) );
      }
    else
      {
      // formulat to be used if hours worked is less than or equal to 40
      grossPay=(wage* hoursWorked);
      }
    
    return grossPay;
    }
    /*****************************************************************************
    double CalculateFederalTax( )
    The purpose of this function is to calculate and return the federal income tax
    to withhold from an employee. It takes two arguments: a double that represents
    the employee's gross pay and an integer argument that represents the number of
    exemptions claimed by the employee.
    *****************************************************************************/
    double CalculateFederalTax( double grossPay, int numExemptions )
    {
    // Declaring variables
    double federal;
    // Formula to be used to determine how much federal tax is taken out of pay
    grossPay = grossPay - (FEDERAL_WITHHOLDING * numExemptions );
    // Setting up if-else-if statement to be used
    if( grossPay < 51 )
      {
      federal = 0;
      }
    else if( grossPay < 552 )
      {
      federal = 0.15 * grossPay;
      }
    else if( grossPay < 1196 )
      {
      federal = 75.15+( grossPay - 552 ) * 0.28;
      }
    else if( grossPay < 2662 )
      {
      federal = 255.47 + ( grossPay -1196 ) * 0.31;
      }
    else if(grossPay <5750)
      {
      federal = 709.93 + ( grossPay - 2662 ) * 0.36;
      }
    else
      {
      federal = 1821 + ( grossPay - 5750 ) * 0.396;
      }
    return federal;
    }
    /*****************************************************************************
    double CalculateStateTax( )
    The purpose of this function is to calculate and return the state income tax
    to withhold from an employee. It takes two arguments: a double that represents
    the employee's gross pay and an integer that represents the number of exemptions
    claimed by the employee.
    *****************************************************************************/
    double CalculateStateTax( double grossPay, int numExemptions )
    {
    // Declaring variables
    double state;
    // Setting up if else statements
    // if gross pay is less than or equal to state exemption * number of exemptions
    if( grossPay <= STATE_EXEMPTION * numExemptions)
      {
      // state tax is 0
      state = 0;
      }
    else
      {
      // state tax is calculated by the following formula
      state = 0.03 * ( grossPay - (STATE_EXEMPTION * numExemptions));
      }
       
    return state;
    }
    /*****************************************************************************
    double CalculateSocialSecurity( )
    The purpose of this function is to calculate and return the amount of social
    security to withhold from an employee. It takes one argument: a double that
    represents the employee's gross pay.
    *****************************************************************************/
    double CalculateSocialSecurity( double grossPay )
    {
    // Declaring variables
    double SS;
    // Formula used to calculate social security tax
    SS = SOCIAL_SECURITY * grossPay;
    return SS;
    }
    /*****************************************************************************
    int ValidInt( )
    The purpose of this function is to get an integer from the user that is within
    a certain range. It takes three arguments: a string that is used as a prompt
    to the user to tell them what number they are entering, an integer that
    represents the smallest integer that the user can enter, and an integer
    that represents the largest integer that the user can enter. The second and
    third arguments will be used to ensure that the user enters a valid value. If
    an invalid value is entered, display an error message and prompt the user to
    re-enter a value. This should be done repeatedly until the user enters a valid
    integer. The function returns the valid integer.
    *****************************************************************************/
    int ValidInt( string prompt, int lowerBound, int upperBound )
    {
    // Declaring variables
    double num;
    cout << prompt << ": ";
    cin >> num;
    // while loop to be used if data entered is above or below the boundaries
    while( num < lowerBound || num > upperBound)
      {
      // Display this "invalid statement" if data is out of the boundaries
      cout << "Error: Entry out of range. Try again. ";
      cout << prompt << ": ";
      cin >> num;                // store the value entered into num
      }
    
    return num;
    }
    /*****************************************************************************
    double ValidDouble( )
    This function is exactly like ValidInt, except that it takes two doubles,
    rather than integers.
    *****************************************************************************/
    double ValidDouble( string prompt, double lowerBound, double upperBound )
    {
    // Declaring variables
    int num;
    cout << prompt << ": ";
    cin >> num;
    // while loop to be used if data entered is above or below the boundaries
    while ( num < lowerBound || num > upperBound )
      {
      // Display this "invalid statement" if data is out of the boundaries
      cout << "Error: Entry out of range. Try again. ";
      cout << prompt << ": ";
      cin >> num;                // store the value entered into num
      }
    return num;
    }
    /*****************************************************************************
    void BarGraph( )
    The purpose of this function is to display a line of asterisks equal to the
    number of weeks that weekly pay has been calculated. It takes one argument: an
    integer that represents the number of weekly pay calculations that have been
    performed. This function returns nothing.
    *****************************************************************************/
    void BarGraph( int numWeeks )
    {
    // Display this cout statement
    cout << " Total Number of Weeks: ";
    // Used to create the bar graph for the number of weeks of pay that were calculated
    for ( int i=0; i < numWeeks; i++ )
      {
      cout << "* ";
      }
    }
    /*****************************************************************************
    int WeekDisplay ()
    The purpose of this function is to display the number of the weekly salary
    that is being calculated and to have it increment by one each time the user
    says yes.
    *****************************************************************************/
    int WeekDisplay (int numWeekDisplay)
    {
    for (int i=1; i < numWeekDisplay; i++ )
      {
      cout << numWeekDisplay;
      }
    return numWeekDisplay;
    }
  
  
   output
  
  
Do you want to calculate your weekly pay? (Y/N) y                                                                                                           
                                                                                                                                                            
Enter the number of hours worked - (minimum: 0, maximum: 60) : 45                                                                                           
Enter the hourly wage - (minimum: $0.00, maximum: $30.00) : 30                                                                                              
Enter the number of exemptions - (minimum: 0, maximum: 5) : 5                                                                                               
                                                                                                                                                            
Week 1:                                                                                                                                                     
You worked 45 hours at $30.00 per hour.                                                                                                                     
Gross Pay:           1425.00                                                                                                                                
Federal Tax:         241.51                                                                                                                                 
State Tax:           36.98                                                                                                                                  
Social Security:     109.01                                                                                                                                 
Net Pay:             1037.49                                                                                                                                
                                                                                                                                                            
Do you want to calculate your weekly pay? (Y/N)                                                                                                             

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote