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
|
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const string EXTENSION1 = ".dat";
const string EXTENSION2 = ".report";
int main ()
{
string baseName, baseName2, baseName3;
string fullName,fullName_payroll1, fullName_payroll2, fullName_payroll3;
string jobDescrip, jobDescrip_payroll1, jobDescrip_payroll2, jobDescrip_payroll3;
string inputFileName, outputFileName;
ifstream masterList, inFile;
ofstream outFile;
float hoursWorked, hoursWorked_payroll1, hoursWorked_payroll2, hoursWorked_payroll3;
float payRate, payRate_payroll1, payRate_payroll2, payRate_payroll3;
float totalPayAmount;
// Variables.
masterList.open("master.lst");
masterList >> baseName >> baseName2 >> baseName3;
inputFileName = baseName + EXTENSION1; // This is operations for first employee listed in the master.lst, ONLY.
outputFileName = baseName + EXTENSION2;
// Opening up the I/O files and naming them according to the data contained within MASTER.LST
// YOU HAVE JUST FIGURED OUT THAT COMMENTING OUT THE OPEN FUNCTION ON THE OUTPUT FILE STREAM MAKES IT WORK. WAS JUST THINKING ABOUT USING CLOSE FOR EACH EMPLOYEE NAME, AND THEN OPEN UP THE NEEDED
//OUTFILE FILE STREAM FOR THE .REPORT. THEN, OPEN UP THE INPUTFILE STREAM, READ IN THE NEEDED VARIABLES, AND OUTPUT THAT TO THE .REPORT.
inFile.open ((inputFileName).c_str());
getline (inFile, fullName); // reading data from the .dat file for .report use
cout << "Contents of fullName: " << fullName << endl;
inFile >> hoursWorked;
cout << "Contents of hoursWorked: " << hoursWorked << endl;
inFile >> payRate;
cout << "Contents of payRate " << payRate << endl;
getline (inFile, jobDescrip);
cout << "Contents of jobDescrip " << jobDescrip << endl;
inFile.close ();
// PUT THE ABOVE DATA OF EMPLOYEE ONE INTO NEEDED VARIABLES FOR FINAL PAYROLL.OUT
fullName_payroll1 = fullName;
hoursWorked_payroll1 = hoursWorked;
payRate_payroll1 = payRate;
jobDescrip_payroll1 = jobDescrip;
// GENERATION OF THE REPORT FILE FOR EMPLOYEE NUMBER 1
outFile.open ((outputFileName).c_str());
outFile << "Dear" << fullName << endl <<
"Last week you worked a total of " << hoursWorked << "hours." << endl;
outFile << "Your pay rate is " << payRate << " per hour." << endl;
outFile << "The amount $ " << payRate * hoursWorked << " has been electronically deposited into your account." <<endl;
outFile << "We appreciate your service as " << jobDescrip << endl;
outFile.close ();
// READING OF DATA FOR SECOND EMPLOYEE
inputFileName = baseName2 + EXTENSION1;
outputFileName = baseName2 + EXTENSION2;
inFile.open ((inputFileName).c_str());
getline (inFile, fullName); // reading data from the .dat file for .report use
cout << "Contents of fullName: " << fullName << endl;
inFile >> hoursWorked;
cout << "Contents of hoursWorked: " << hoursWorked << endl;
inFile >> payRate;
cout << "Contents of payRate " << payRate << endl;
getline (inFile, jobDescrip);
cout << "Contents of jobDescrip " << jobDescrip << endl;
inFile.close ();
// PUT THE ABOVE DATA OF EMPLOYEE TWO INTO NEEDED VARIABLES FOR FINAL PAYROLL.OUT
fullName_payroll2 = fullName;
hoursWorked_payroll2 = hoursWorked;
payRate_payroll2 = payRate;
jobDescrip_payroll2 = jobDescrip;
// GENERATION OF REPORT FILE FOR EMPLOYEE NUMBER 2
outFile.open ((outputFileName).c_str());
outFile << "Dear" << fullName << endl <<
"Last week you worked a total of " << hoursWorked << "hours." << endl;
outFile << "Your pay rate is " << payRate << " per hour." << endl;
outFile << "The amount $ " << payRate * hoursWorked << " has been electronically deposited into your account." <<endl;
outFile << "We appreciate your service as " << jobDescrip << endl;
outFile.close ();
// NOW FOR DATA READING OF EMPLOYEE NUMBER 3
inputFileName = baseName3 + EXTENSION1;
outputFileName = baseName3 + EXTENSION2;
inFile.open ((inputFileName).c_str());
getline (inFile, fullName); // reading data from the .dat file for .report use
cout << "Contents of fullName: " << fullName << endl;
inFile >> hoursWorked;
cout << "Contents of hoursWorked: " << hoursWorked << endl;
inFile >> payRate;
cout << "Contents of payRate " << payRate << endl;
getline (inFile, jobDescrip);
cout << "Contents of jobDescrip " << jobDescrip << endl;
inFile.close ();
// PUT THE ABOVE DATA OF EMPLOYEE THREE INTO NEEDED VARIABLES FOR FINAL PAYROLL.OUT
fullName_payroll3 = fullName;
hoursWorked_payroll3 = hoursWorked;
payRate_payroll3 = payRate;
jobDescrip_payroll3 = jobDescrip;
// GENERATION OF .REPORT FOR EMPLOYEE NUMBER 3
outFile.open ((outputFileName).c_str());
outFile << "Dear" << fullName << endl <<
"Last week you worked a total of " << hoursWorked << "hours." << endl;
outFile << "Your pay rate is " << payRate << " per hour." << endl;
outFile << "The amount $ " << payRate * hoursWorked << " has been electronically deposited into your account." <<endl;
outFile << "We appreciate your service as " << jobDescrip << endl;
outFile.close ();
// GENERATION OF THE PAYROLL.OUT OUTPUT FILE
ofstream payRoll_Out;
payRoll_Out.open ("payroll.out");
payRoll_Out << fullName_payroll1 << ", " << hoursWorked_payroll1 << ", " << payRate_payroll1 * hoursWorked_payroll1 << endl;
payRoll_Out << fullName_payroll2 << ", " << hoursWorked_payroll2 << ", " << payRate_payroll2 * hoursWorked_payroll2 << endl;
payRoll_Out << fullName_payroll3 << ", " << hoursWorked_payroll3 << ", " << payRate_payroll3 * hoursWorked_payroll3 << endl;
totalPayAmount = (payRate_payroll1 * hoursWorked_payroll1) + (payRate_payroll2 * hoursWorked_payroll2) + (payRate_payroll3 * hoursWorked_payroll3);
payRoll_Out << "TOTAL PAYROLL: " << "$" << totalPayAmount << endl;
return 0;
}
|