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
|
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const string IN_NAME_EXT= ".dat.txt";
const string REPORT_NAME_EXT= ".report.txt";
int main () {
//Declare variables
string employeeName, jobDescription
, inputFileName, baseFileName
, reportFileName;
float hoursWorked, payRate, payAmount
, totalPayRoll, salary;
totalPayRoll=0;
ifstream masterFile;
ifstream reportFileE1;
ofstream memoFileE1;
ofstream payRoll;
masterFile.open("master.lst.txt");
if (masterFile.is_open()){
cout << "File succcesfully opened\n" << endl;
} else {
cout << "Unable to open the file master.lst" << endl;
}
//open info files
payRoll.open("payroll.out.txt");
//process 1st employee
//////////////////////////////////////////////////
//Get base name from master file
masterFile >> baseFileName;
inputFileName= baseFileName + IN_NAME_EXT;
//input file name is the name of the entire file
//base file name is the name of the employee
//INPUT_NAME_EXT is the program extension
//(ie .txt .doc etc)
//Make file names from base name
reportFileE1.open(inputFileName.c_str());
if (reportFileE1.is_open()){
cout << "File succcesfully opened\n" << endl;
} else {
cout << "Unable to open the file" << endl;
}
cout << fixed << setprecision(2);
//Open files
reportFileName= baseFileName + REPORT_NAME_EXT;
memoFileE1.open(reportFileName.c_str());
//I'm pretty sure I need cin.ignore here,
//but where ever I put it just messes up
//program even more.
getline(reportFileE1,employeeName);
reportFileE1 >> hoursWorked >> payRate;
getline(reportFileE1, jobDescription);
salary = payAmount * payRate;
cout << employeeName << endl;
cout << hoursWorked << " " << payRate << endl;
cout << jobDescription << endl;
cout << endl << endl << endl;
//Write employee report
memoFileE1 << "Dear " << employeeName << endl
<< "Last week you worked a total of " << hoursWorked
<< " per hour." << endl << "The amount $"
<< salary << " has been electronically deposited "
<< "your account.\n\nWe appreciate your service as "
<< jobDescription << "." << endl;
//Cout employee report
cout << "Dear " << employeeName << endl
<< "Last week you worked a total of " << hoursWorked
<< " per hour." << endl << "The amount $"
<< salary << " has been electronically deposited "
<< "your account.\n\nWe appreciate your service as "
<< jobDescription << "." << endl;
//Close files
reportFileE1.close();
memoFileE1.close();
//accumulate totals
totalPayRoll= totalPayRoll+ salary;
///////////////////////////////////////////////////////////////
//***Make sure to do 3 more times***
//write totalPayRoll File
payRoll << employeeName << " , " << hoursWorked
<< ", " << salary << endl << endl
<< "Total Payroll $" << totalPayRoll << endl;
//****** Be sure to format to 2 decimal places *******
//close files
payRoll.close();
masterFile.close();
return (0);
}
|