// FILE: prcsemp1.cc // PROCESS ALL EMPLOYEES AND COMPUTE TOTAL PAYROLL AMOUNT #include "copyline.cc" #include "skipnwln.cc" void process_emp (ifstream& eds, // IN: employee file stream ofstream& pds, // OUT: payroll file stream float& payroll) // OUT: total company payroll // Pre: eds and pds are prepared for input/output. // Post: All employee data are copied from eds to pds and // the sum of their salaries is returned through payroll. // Uses: copy_line(); skip_new_line; { // Functions used ... // COPY ONE LINE OF TEXT int copy_line (ifstream&, // IN: employee file stream ofstream&); // OUT: payroll file stream // SKIP NEW LINE void skip_newline (ifstream&); // IN: stream to file involved // Local data ... float hours; // input: hours worked. float rate; // input: hourly rate. float salary; // output: gross salary. // set for floating point output pds.precision (2); pds.setf (ios::fixed | ios::showpoint); payroll = 0.0; while (!eds.eof ()) { // Copy employee name. copy_line (eds, pds); if (eds.eof ()) break; // Get salary data. eds >> hours >> rate; if (eds.eof ()) break; skip_newline (eds); salary = hours * rate; pds << salary << endl; payroll += salary; } // end while return; } // end process_emp