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
|
#include <iostream> // library for input/output
#include <conio.h> // console input/output
#include <iomanip> // Controls output formatting
#include <fstream>
#include <string>
using namespace std;
void GetData(ifstream&, string&, double&, double&);
void GetWeeklySalary(double, double, double&);
void GetNumOfEmployee(int&);
void GetAvgHours(int, double, double&);
void GetAvgWeeklySalary(int, double, double&);
void GetTotalHours(double&, double&);
void GetTotalWeeklySalary(double&, double&);
int main()
{
// declaration section
ifstream inData;
ofstream outData;
string employeeName;
int numOfEmployees = 0;
double hoursWorked;
double hourlyPay;
double totalHours = 0;
double avgHours;
double totalWeeklySalary = 0;
double avgWeeklySalary;
double weeklyPay;
// input section
inData.open("dataA.txt");
outData.open("output1256.txt");
//processing section
outData << fixed << showpoint << setprecision(2);
outData << "Employee Name" << setw(20) << "Hours Worked" << setw(20) << "Hourly Pay" << setw(20) << "Weekly Salary" << endl;
GetData(inData, employeeName, hoursWorked, hourlyPay); // Priming Read
while( !inData.eof() )
{
GetData(inData, employeeName, hoursWorked, hourlyPay);
GetWeeklySalary(hoursWorked, hourlyPay, weeklyPay);
GetTotalHours(totalHours, hoursWorked);
GetTotalWeeklySalary(totalWeeklySalary, weeklyPay);
GetNumOfEmployee(numOfEmployees);
outData << setw(10) << employeeName << setw(20) << hoursWorked << setw(20) << hourlyPay << setw(20) << weeklyPay << endl;
}
outData << "\nNumber of Employees" << setw(20) << "Total Hrs Worked" << setw(25) << "Average Hrs Worked" << setw(30)
<< "Total Weekly Salary" << setw(35) << "Average Weekly Salary" << endl;
GetAvgHours(numOfEmployees, totalHours, avgHours);
GetAvgWeeklySalary(numOfEmployees, totalWeeklySalary, avgWeeklySalary);
outData << setw(10) << numOfEmployees << setw(25) << totalHours << setw(23) << avgHours << setw(30)
<< totalWeeklySalary << setw(35) << avgWeeklySalary << endl;
inData.close();
outData.close();
_getch();
return 0;
}
void GetData(ifstream& inData, string& employeeName, double& hoursWorked, double& hourlyPay)
{
inData >> employeeName >> hoursWorked >> hourlyPay;
}
void GetWeeklySalary(double hoursWorked, double hourlyPay, double &weeklyPay)
{
double totalOvertimeHours;
if( hoursWorked > 40 )
{
totalOvertimeHours = hoursWorked - 40;
weeklyPay = ( (hourlyPay * 40) + ((hourlyPay * 1.5) * totalOvertimeHours));
}
else
{
weeklyPay = hoursWorked * hourlyPay;
}
}
void GetNumOfEmployee(int& numOfEmployee)
{
numOfEmployee++;
}
void GetAvgHours(int numOfEmployees, double totalHours, double &avgHours)
{
avgHours = totalHours / numOfEmployees;
}
void GetAvgWeeklySalary(int numOfEmployees, double totalWeeklySalary, double &avgWeeklySalary)
{
avgWeeklySalary = totalWeeklySalary / numOfEmployees;
}
void GetTotalHours(double &totalHours, double &hoursWorked)
{
totalHours += hoursWorked;
}
void GetTotalWeeklySalary(double &totalWeeklySalary, double &weeklyPay)
{
totalWeeklySalary += weeklyPay;
}
|