1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
//P06 Call-by-reference - Robert Ruckman
/*
This program is used by customers to determine what the cost
of their order would be based on the price and quantity ordered.
*/
#include <iostream> // cin, cout
using namespace std;
void inputRate (double& rate);
void inputHours (int& hours);
void calcGross (double rate, int hours, double& gross);
void calcTax (double gross, double taxRate, double *taxAmount);
double calcNetPay (double gross, double FICA, double federal, double state, double UNION_DUES);
double calcNetHourly (double netpay, int hours);
const double OVERTIME_RATE = 1.5;
void main ()
{
const double UNION_DUES = 10.00, FICA_RATE = (0.06),
FEDERAL_RATE = (0.15), STATE_RATE = (0.05);
int hours;
double rate, gross, fica, federal, state, netPay, netHourly, taxRate, taxAmount;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "P06 Call by reference - Robert Ruckman \n\n";
inputRate (rate);
inputHours (hours);
calcGross (rate, hours, gross);
calcTax (gross, FICA_RATE, &fica);
calcTax (gross, FEDERAL_RATE, &federal);
calcTax (gross, STATE_RATE, &state);
taxRate = FICA_RATE, FEDERAL_RATE, STATE_RATE;
gross = rate * hours;
taxAmount = gross * taxRate;
netPay = gross - (FICA_RATE + FEDERAL_RATE + STATE_RATE + UNION_DUES);
netHourly = netPay / hours;
cout << endl
<< "Hourly Rate: \t" << rate << endl
<< "Hours Worked: \t" << hours << endl
<< "Gross Pay: \t" << gross << endl
<< "FICA: \t" << fica << " at " << FICA_RATE << endl
<< "Federal Tax: \t" << federal << " at " << FEDERAL_RATE << endl
<< "State Tax: \t" << state << " at " << STATE_RATE << endl
<< "Union Dues: \t" << UNION_DUES << endl
<< "NetPay: \t" << netPay << endl
<< "NetHourly: \t" << netHourly << endl;
cout << "\nThank you!\n\n";
return;
} // end of main
int hours;
double rate, gross, FICA_RATE, FEDERAL_RATE, STATE_RATE, UNION_DUES, netPay, netHourly;
void inputRate (double& rate)
{
do
{
cout << "Enter a rate between $10 and $15: ";
cin >> rate;
} while (rate < 10 || rate > 15);
cout << endl;
return;
}
void inputHours (int& hours)
{
hours = 0;
while (hours < 1 || hours > 50)
{
cout << "Enter hours worked between 1 and 50 for the week: ";
cin >> hours;
}
return;
}
void calcGross (double, int, double& gross)
{
if (hours > 40)
gross = hours * (rate * OVERTIME_RATE);
else
gross = hours * rate;
return;
}
void calcTax (double gross, double taxRate, double *taxAmount)
{
*taxAmount = gross * taxRate;
return;
}
double calcnetPay (double gross, double FICA_RATE, double FEDERAL_RATE, double STATE_RATE, double UNION_DUES)
{
netPay = gross - (FICA_RATE + FEDERAL_RATE + STATE_RATE + UNION_DUES);
return (netPay);
}
double calcNetHourly (double netpay, int hours)
{
netHourly = netPay / hours;
return (netHourly);
}
//end of program
|