Hello! I've been posting for a little while. I truly appreciate the help I find here at cplusplus. THANK YOU!!!!
Ok, I have to learn about arrays, and what better way to learn than to code? Right?
I have an input file and an output file. The input file is being opened successfully, read successfully and closed successfully. The output file is being created successfully, written to successfully and closed successfully.
The data that is in the input file is provided below the code I have attached here.
If the program runs smoothly the following will occur:
Report the number of records read in;
Report the employees with the Max and Min wages;
Report the average of the wages;
Print a final report that includes all additional calculations.
Additional calculations are as follows:
Add $50 bonus to the gross pay of any person working more than 45 hours;
Fine an employee 0.25 cents an hour if they work less than 30 hours.
MUST HAVES in the code:
3 arrays minimum: employee_name; hourly_wage; hours_worked.
3 functions minimum: process_payroll; process_employee; print_results.
AND ----
There will be at least 10 names read in. Output an error message when more than 10 files have been read in, and continue to calculate the data with the additional names.
The max and min. wages must be calculated before the fines are levied.
The output file I receive so far is attached below the input file data after the code.
Again, thank you for the help.
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
/*This program satisfies CS1 SP14 Proj 2. Practice in array processing.
Written By: Ashley Julin
Date: 03/03/2014
"I have neither given nor received unauthorized aid in completing this work, nor have I presented someone else's work as my own."
*/
#include <iostream> //input output stream
#include <fstream> //file stream
#include <iomanip> //input output manipulation
using namespace std;
//Function Prototype
bool process_employee (ifstream& inFile);
void process_payroll (ifstream& inFile);
void print_results(ofstream& outFile);
int main()
{
double gross = 0;
double bonus = 0;
double adjGross = 0;
//Declare file to be read from
ifstream inFile;
inFile.open("empInFile.txt");//open the file
if(!inFile)
{
cout << "\n\nThe input file has not opened.\n"
<< "Check that the file exists.\n" << endl;
system("pause");
exit(1);
}//IF statement to test that the inFile opens
//Calls to the process_payroll funtion to perform calculations
process_payroll(inFile);
system("pause");
return 0;
}//main
//This function reads the employee information from the input file and returns them through referenced variables
//if the employee information is read successfully it returns 1 otherwise it returns 0.
bool process_employee (ifstream& inFile)
{
//Declare arrays
char employee_name [15];
double hourly_wage [15];
int hours_worked [15];
if(inFile >> employee_name, hourly_wage, hours_worked)
return 1;
else
return 0;
}// process_employee function
//This function prints the header message and column headings;
//calls the process_employee function from inside a loop until 0 is returned;
//calculates and updates all variables needed for output in both
//process_payroll and print_summary functions.
void process_payroll (ifstream& inFile)
{
//Local Declarations
ofstream outFile;
//Open the outFile
outFile.open("empReport.txt");//open the file
if(!outFile)
{
cout << "\n\nThe output file has not opened.\n"
<< endl;
system("pause");
exit(1);
}//IF statement to test that the outFile opens
//Calling process_employee function from inside a loop until zero is returned.
while (process_employee(inFile))
{
//Calls to the print_summary function to output all calculations
print_results(outFile);
}
//*******************************************************************
//close the ifstream inFile connection between the program and the file input.txt
inFile.close();
return;
}
//This function prints out the Summary message;
//prints out the column headings;
//prints out the totals which have been accumulating from the process_payroll function.
void print_results(ofstream& outFile)
{
//Local Declarations
int hours = 0;
int rate = 0;
int minWage = 0;
int maxWage = 0;
double minValue = 100;
double maxValue = 0;
double totAvg = 0;
//Declare arrays
char employee_name [15];
double hourly_wage [15];
int hours_worked [15];
int empFiles = employee_name[15];
//Statements
for(int i = 0; i < empFiles; i++)
{
if(hourly_wage[i] > maxValue)
{
maxValue = hourly_wage[i];
maxWage = i;
}
if(minValue > hourly_wage[i])
{
minValue = hourly_wage[i];
minWage = i;
}
totAvg = totAvg + hourly_wage[i];
}//For Loop
//The output of the minimum and maximum wage calculations and the average wage
outFile << "\n\nThe number of records read: " << empFiles << "\n"
<< "Maximum Pay Rate: " << employee_name[maxWage] << " @ $" << hourly_wage[maxWage] << "\n"
<< "Minimum Pay Rate: " << employee_name[minWage] << " @ $" << hourly_wage[minWage] << "\n"
<< "Average Pay: $" << totAvg / empFiles << endl;
if(empFiles >= 10)
{
outFile << "More than 10 names have been read in."<<endl;//error processing in case more than 10 names are attempted to be read in.
}
outFile << "\n\nOctober 2009 Payroll:\t\t\n\n";
outFile << "Employee Name Hours Rate Gross Bonus Adjusted_Gross" << endl;
outFile << "\n\n\n";
//format the ouput data
outFile << std::fixed << setprecision(2) ;
//*****************************************************************
//Calculate the max and min wages
//******************************************************************
//Begin a series of true or false tests with IF Statements and specific expressions for each scenario
if(hours_worked[hours] > 45)//IF Statement for hours greater than 45
{
//Local declaration
double gross = (hourly_wage[rate] * hours_worked[hours]);
char bonus = 'Y';
double adjGross = gross + 50;
//Statements
outFile << "\n "<< employee_name
<< "\t" << hours_worked[hours] << "\t"
<< hourly_wage[rate] << "\t"
<< gross << "\t"
<< bonus << "\t"
<< adjGross << endl;
}//IF Statement for hours greater than 45
//***************************************************
//***************************************************
if(hours < 30)//IF Statement for hours less than 30
{
//Local Declarations and Statements of expressions for calculating each variable
double gross = (hourly_wage[rate] * hours_worked[hours]);
char bonus = 'N';
double adjGross = gross - (hourly_wage[rate] * hours_worked[hours]) - (hours_worked[hours] * .25);
//Statements
outFile<< "\n "<< employee_name
<< "\t" << hours << "\t"
<< rate << "\t"
<< gross << "\t"
<< bonus << "\t"
<< adjGross << endl;
}//IF Statement for hours less than 30
//***************************************************
if(hours >= 30 && hours <=44)//IF Statement for hours between 35 and 44
{
//Local Declarations
double gross = (hourly_wage[rate] * hours_worked[hours]);
char bonus = 'N';
double adjGross = gross;
//Statements
outFile<< "\n "<< employee_name
<< "\t" << hours << "\t"
<< rate << "\t"
<< gross << "\t"
<< bonus << "\t"
<< adjGross << endl;
}//IF Statement for hours between 35 and 44
//****************************************************
//******************************************************************
outFile.close();
return;
}//print_summary
//control passes back to the main function to system("pause")
|
Input file data:
Clinton 10.00 10
Lincoln 15.00 50
Washington 32.00 35
Kennedy 4.99 45
Nixon 10.00 25
Archer 67.76 10
Kilpatrick 15.00 20
Young 18.67 34
Winston 12.00 40
Jackson 17.24 23
Johnson 44.00 80
Kennedy 3.99 15
Lincoln 12.19 56
Nixon 19.00 40
Regan 38.66 20
Rosevelt 21.00 20
Obama 48.90 20
Truman 12.12 67
Washington 30.00 21
Wilson 45.09 59
Output file at current debugging:
The number of records read: -52
Maximum Pay Rate: Ì @ $-9.25596e+061
Minimum Pay Rate: Ì @ $-9.25596e+061
Average Pay: $-9.25596e+061
More than 10 names have been read in.
October 2009 Payroll:
Employee Name Hours Rate Gross Bonus Adjusted_Gross
ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ 0 0 79508117989074975000000000000000000000000000000000000000000000000000000.00 N 214748365.00