My assignment is to rewrite the attached code in C++ using call-by-references and pointers. I am having a hard time understanding how to use call-by-references and pointers in the context of this program:
#include
using namespace std;
//Functions
double inputRate();
int inputHours();
double calcGross(double rate, int hours);
double calcTax(double gross, double taxRate);
//Global Constant
const double OVERTIME_RATE = 1.5;
void main()
{
//Local Constants
const double UNION_DUES = 10.00, FICA_RATE = (0.06),
FEDERAL_RATE = (0.15), STATE_RATE = (0.05);
//Local Variables
int hours;
double rate, gross, fica, federal, state, netpay, netHourly;
//Decimal Formatting
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout
//Input Values
rate = inputRate();
hours = inputHours();
//Calculations
gross = calcGross(rate, hours);
fica = calcTax(gross, FICA_RATE);
federal = calcTax(gross, FEDERAL_RATE);
state = calcTax(gross, STATE_RATE);
//Remaining calculations
netpay = gross - (fica + federal + state + UNION_DUES);
netHourly = netpay / hours;
//Display Results and Echo the Input
cout
system("pause");
} //End of Main
//Hourly Rate Prompt with check for rate between 10 and 15
double inputRate()
{
double rate;
do
{
cout cin >> rate;
} while (rate 15.00);
cout
return (rate);
}
//Hours prompt with check for hours between 1-50
int inputHours()
{
int hours;
do
{
cout cin >> hours;
} while (hours 50);
cout
return (hours);
}
double calcGross(double rate, int hours)
{
double gross;
if (hours > 40)
gross = (40 * rate) + ((hours - 40) * rate * OVERTIME_RATE);
else
gross = rate * hours;
return gross;
}
double calcTax(double gross, double taxRate)
{
double taxAmount;
taxAmount = gross * taxRate;
return taxAmount;
}
Download Attachment:
example.cpp
Get Free Quote!
404 Experts Online