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 119
|
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
float grosspay(float hours, float payRate);
float otgross(float hours, float payRate);
float totalDeductions(float gross, float dependents, float retirement);
void drawLine();
// Named constant definitions (and function declarations):
const float taxes = .23;
const float social = .08;
const float insurance = 12;
float gross, deductions;
ifstream indata;
// Main program:
int main()
{
float hours, payRate, net, dependents, retirement;
string name;
char e;
int count;
indata.open("Pay.dat");
cout << showpoint << fixed;
//get name from file
//loop
while(!indata.eof())
{
//get name, prompt for hours
getline(indata,name);
cout << "How many hours did " << name << " work?" << endl;
cin >> hours;
//get payrate, dependents, retirement from file
indata >> payRate;
indata >> dependents;
indata >> retirement;
//run functions
grosspay(hours, payRate);
otgross(hours, payRate);
totalDeductions(gross, dependents, retirement);
//clear screen, calculate net, output data
system("cls");
net = gross - deductions;
drawLine();
cout << setprecision(2);
cout << "Name:" << right << setw(26) << name << endl;
cout << "Gross Pay:" << right << setw(15) << "$" << gross << endl;
cout << "Total Deductions:" << right << setw(8) << "$" << deductions << endl;
cout << "Net Pay:" << right << setw(17) << "$" << net << endl;
drawLine();
drawLine();
//prompt to exit or continue
cout << "Press 'c' to request next person or 'e' to exit." << endl;
cin >> e;
if(e == 'e')
exit(1);
}
return 0;
} //end function main
//Variable declarations:
float grosspay(float hours, float payRate)
{
gross = hours * payRate;
return gross;
}
float otgross(float hours, float payRate)
{
//if hours > 40 find overtime
if(hours > 40)
{
gross = (gross - ((hours - 40) * payRate)) + ((hours - 40) * (payRate * 1.5));
return gross;
}
else
return gross;
}
float totalDeductions(float gross, float dependents, float retirement)
{
float taxAmount, ssAmount, insAmount, retireAmount;
//calculate taxes, social, insurance, retirement amounts
taxAmount = taxes * gross;
ssAmount = social * gross;
insAmount = 12 * dependents;
retireAmount = (retirement / 100) * gross;
//find total
deductions = taxAmount + ssAmount + insAmount + retireAmount;
return deductions;
}
void drawLine()
{
cout << "===============================" << endl;
}
|