// FILE: payroll.cc // WRITES EACH EMPLOYEE NAME AND GROSS SALARY TO AN // OUTPUT FILE AND COMPUTES TOTAL PAYROLL AMOUNT #include // required for file streams #include // for definition of EXIT_FAILURE #include "prcsemp1.cc" // process employee // ASSOCIATE PROGRAM IDENTIFIERS WITH EXTERNAL FILE NAMES #define in_file "Emp_File.dat" // employee file #define out_file "Salary.dat" // payroll file int main() { // Functions used ... // PROCESS ALL EMPLOYEES AND COMPUTE TOTAL void process_emp (ifstream&, // IN: employee data stream ofstream&, // OUT: payroll data stream float&); // OUT: total company payroll // Local data ... ifstream eds; // input: employee data stream ofstream pds; // output: payroll data stream float total_payroll; // output: total payroll // Prepare files. eds.open (in_file); if (eds.fail()) { cerr << "*** ERROR: Cannot open " << in_file << " for input." << endl; return EXIT_FAILURE; } pds.open(out_file); if (pds.fail ()) { cerr << "*** ERROR: Cannot open " << out_file << " for output." << endl; eds.close (); return EXIT_FAILURE; } // Set precision and flags for floating point output. cout.precision (2); cout.setf (ios::fixed | ios::showpoint); // Process all employees and compute total payroll. process_emp (eds, pds, total_payroll); // Display result. cout << "Total payroll is $" << total_payroll << endl; // Close files. eds.close (); pds.close (); return 0; }