Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Timely Talent temporary Help Agency maintains an employee master file that c

ID: 3763869 • Letter: T

Question

The Timely Talent temporary Help Agency maintains an employee master file that contains an employee Id number, last name, first name, address, and hourly rate for each temporary worker. The file has been sorted in employee ID number order. Each week, a trasaction file is created with a job number, address, customer name, employee ID, and hours worked for every job filled by Timely Talent workers. the transaction file is also sorted in employee ID order.

a. Design the logic for a program that matches the current week's transaction file records to the master file and outputs one line for each transaction, indicating job number, employee ID number, hours worked, hourly rate, and gross pay. Assume that each temporary worker works at most one job per week. Output one line for each worker, even if the worker has completed no jobs during the current week.

b. Modify the help agency program to output lines only for workers who have completed at least one job during the current week.

c. Modify the help agency program so that any temporary worker can work any number of seperate jobs during the week. Output one line for each job that week.

d. Modify the help agency program so that it accumulates the worker's total pay for all jobs in a wekk and outputs one line per worker.

Explanation / Answer

include <fstream>       //required for file streams
#include <iostream>
#include <cstdlib>       //for definition of EXIT_FAILURE

using namespace std;

#define inFileEmp "employees.txt"   //employee file
#define inFileHour "hours.txt"       //hour file
#define outFile "pay.txt"       //payroll file

//Functions used
void processEmp (ifstream&, ifstream&, ofstream&);   //process all employees and display name, pay, etc

int main()
{
   ifstream eds;       //input: employee data stream
   ifstream hrds;       //input: hour data stream
   ofstream pds;       //output: all info per employee

   //Prepare files
   eds.open(inFileEmp);
   if (eds.fail())
   {
       cerr << "*** ERROR: Cannot open " << inFileEmp << " for input." << endl;
       return EXIT_FAILURE;   //failure return
   }
  
  
   hrds.open(inFileHour);
   if (hrds.fail())
   {
       cerr << "*** ERROR: Cannot open " << inFileHour << " for input." << endl;
       return EXIT_FAILURE;   //failure return
   }
  
  
   pds.open(outFile);
   if (pds.fail())
   {
       cerr << "*** ERROR: Cannot open " << outFile << " for output." << endl;
       return EXIT_FAILURE;   //failure return
   }
  
   processEmp(eds,
       hrds,
       pds);

   //Close files
   eds.close();
   hrds.close();
   pds.close();
  
   return 0;
}

void processEmp
   (ifstream& eds,
   ifstream& hrds,
   ofstream& pds)
{
   string name;       //input: employee name from inFileEmp
   int id1;       //input: employee id from inFileEmp
   float rate;       //input: employee pay rate from inFileEmp
   int id2;       //input: employee id from inFileHour
   int hours;       //input: employee hours worked from inFileHour
   float pay;       //output: pay
   int noHours = 0;
      
  
   hrds >> id2 >> hours;
   while (!hrds.eof())
   {
       eds >> name >> id1 >> rate;
       pay = rate * hours;
       if (id1 == id2)
       {
           pds << name << " " << id1 << " " << rate << " " << hours << " $" << pay << endl;
           hrds >> id2 >> hours;
       }
       else if (id1 != id2)
       {
           eds >> name >> id1 >> rate;
       }
       else (eds.eof());
       {
           pds << name << " " << id1 << " " << rate << " " << hours << " $" << noHours << endl;
           hrds >> id2 >> hours;
       }

   }
}

output:

employees.txt
Andrea 1541 7.27
Barry 3794 9.64
Chantal 6260 9.39
Dorian 4740 9.20
Erin 7692 9.18
Fernand 4360 7.14
Gabrielle 2442 8.74
Humberto 5669 9.39
Ingrid 6512 9.16
Jerry 5255 8.08

hours.txt
1541 47
6260 36
4740 37
7692 23
4360 34
2442 25
5669 45
5255 49

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote