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

// This program calculates gross pay. #include <iostream> #include <string> usin

ID: 3684180 • Letter: #

Question

// This program calculates gross pay.
#include <iostream>
#include <string>
using namespace sdt;

// Global constants
const double PAY_RATE = 22.55;           // Hourly pay rate
const double BASE_HOURS = 40.0;       // Max non-overtime hours
const double OT_MULTIPLIER = 1.5;     // Overtime multiplier

// Function prototypes
double getBasePay(double);
double getOvertimePay (double);

int main()
{
     double hours,
     basePay,
     overtime = 0.0,
     totalPay;

     // Get the number of hours worked.
     cout << "How many hours did you work? ";
     cin >> hours;

     // Get the amount of base pay.
     basePay = getBasePay(hours);

     // Get overtime pay, if any.
     if (hours > BASE_HOURS)
        overtime = getOvertimePay(hours);

     // Set up numeric output formatting.
     cout << setprecision(2) << fixed << showpoint;

     // Display the pay.
     cout << "Base pay: $" << basePay << endl
             << "Overtime pay $" << overtime << endl
             << "Total pay $" << totalPay << endl;

     return 0;

}

//***********************************************************
// The getBasePay function accepts the number of   *
// hours worked as an argument and returns the       *
// employee's pay for non-overtime hours.                 *
//***********************************************************

double getBasePay(double hoursWorked)
{
     double basePay;     // To hold base pay

     // Determine base pay.
     if (hoursWorked > BASE_HOURS)
        basePay = BASE_HOURS * PAY_RATE;
     else
        basePay = hoursWorked * PAY_RATE;

     return basePay;

}

//***********************************************************
// The getOvertimePay function accepts the number *
// of hours worked as an argument and returns the    *
// employee's overtime pay.                                        *
//***********************************************************

double getOvertimePay(double hoursWorked)
{
     double overtimePay;   // to hold overtime pay

     // Determine overtime pay.
     if (hoursWorked > BASE_HOURS)
     {
         overtimePay = (hoursWorked - BASE_HOURS) *
                       PAY_RATE * OT_MULTIPLIER;

     }
     else
          overtimePay = 0.0;

     return overtimePay;

}

OUTPUT
How many hours did you work? 48 [Enter]
Base pay: $902.00
Overtime pay: $270.60
Total pay: $1172.60

QUESTIONS******1) Write a function named calculateTax()
2) Call the function calculateTax()
3) In the function calculateTax(), ask the user to enter the tax rate
4) Use the tax rate entered by the user to calculate tax owed.
5) Display tax owed in the output to the screen in addition to the other output already produced by the program.

Explanation / Answer

// This program calculates gross pay.
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;
// Global constants
const double PAY_RATE = 22.55; // Hourly pay rate
const double BASE_HOURS = 40.0; // Max non-overtime hours
const double OT_MULTIPLIER = 1.5; // Overtime multiplier
// Function prototypes
double getBasePay(double);
double getOvertimePay (double);
double calculateTax(double);

int main()
{
double hours,
basePay,
overtime = 0.0,
totalPay,
tax;
// Get the number of hours worked.
cout << "How many hours did you work? ";
cin >> hours;
// Get the amount of base pay.
basePay = getBasePay(hours);
// Get overtime pay, if any.
if (hours > BASE_HOURS)
overtime = getOvertimePay(hours);
// Set up numeric output formatting.

totalPay = basePay + overtime;

tax = calculateTax(totalPay);

cout << setprecision(2) << fixed << showpoint;
// Display the pay.
cout << "Base pay: $" << basePay << " Overtime pay $" << overtime
<< " Total pay $" << totalPay << " Total tax = $"<<tax<<" Net pay = $"<<totalPay - tax<<endl;
return 0;
}
//***********************************************************
// The getBasePay function accepts the number of *
// hours worked as an argument and returns the *
// employee's pay for non-overtime hours. *
//***********************************************************
double getBasePay(double hoursWorked)
{
double basePay; // To hold base pay
// Determine base pay.
if (hoursWorked > BASE_HOURS)
basePay = BASE_HOURS * PAY_RATE;
else
basePay = hoursWorked * PAY_RATE;
return basePay;
}
//***********************************************************
// The getOvertimePay function accepts the number *
// of hours worked as an argument and returns the *
// employee's overtime pay. *
//***********************************************************
double getOvertimePay(double hoursWorked)
{
double overtimePay; // to hold overtime pay
// Determine overtime pay.
if (hoursWorked > BASE_HOURS)
{
overtimePay = (hoursWorked - BASE_HOURS) *
PAY_RATE * OT_MULTIPLIER;
}
else
overtimePay = 0.0;
return overtimePay;
}

//***********************************************************
// The calculateTax function accepts the number *
// total payment as an argument and returns the *
// employee's tax incurred. *
//***********************************************************
double calculateTax(double totalPay)
{
   double taxRate, tax;
   cout<<"Enter tax rate(in perentage): ";
   cin>>taxRate;
   tax = totalPay*taxRate/100.00;
   return tax;
}