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
|
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
using namespace std;
void GetData (string &name, int &idNum, float &hoursWorked, float &hourlyRate);
void computePay (float &hoursWorked, float &hourlyRate, float &grossPay);
void printReport (string name, int idNum, float hoursWorked, float hourlyRate, float grossPay);
char another;
int idNum;
string name;
float hourlyRate;
float hoursWorked;
float grossPay;
int main ()
{
do
{
GetData (name, idNum, hoursWorked, hourlyRate);
computePay (hoursWorked, hourlyRate, grossPay);
printReport (name, idNum, hoursWorked, hourlyRate, grossPay);
cout << "Would you like to enter in another employee (y/n)? \t ";
cin >> another;
}
while (another != 'n');
}
void
GetData (string & name, int &idNum, float &hoursWorked, float &hourlyRate)
{
cout << "Please enter your first and last name separated by a space:\t";
getline(cin, name);
cout << "Please enter the four digit employee I.D. number:\t";
cin >> idNum;
cout << "Please enter the hours worked:\t";
cin >> hoursWorked;
cout << "Please enter the hourly rate of pay:\t";
cin >> hourlyRate;
}
void
computePay (float &hoursWorked, float &hourlyRate, float &grossPay)
{
if (hoursWorked <= 40)
{
grossPay = hoursWorked * hourlyRate;
}
else if (hoursWorked <= 60)
{
grossPay = (hourlyRate * 40) + (hoursWorked - 40) * 1.5 * hourlyRate;
}
else
{
grossPay = (hourlyRate * 40) + (30 * hourlyRate) + (hoursWorked - 60) * 2.0 * hourlyRate;
}
}
void
printReport (string name, int idNum, float hoursWorked, float hourlyRate, float grossPay)
{
cout << "Employee Name:\t" << name << endl;
cout << "Employee I.D:\t" << setw (4) << setfill ('0') << idNum << endl;
cout << "Hours worked:\t" << hoursWorked << endl;
cout << "Hourly rate:\t" << hourlyRate << endl << endl;
cout << fixed;
cout.precision (2);
cout << "Gross Pay:\t$" << grossPay << endl << endl;
}
| |