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

Lab 02: SEQUENTIAL ACCESS FILES Write a program to read data stored in \"workers

ID: 3539658 • Letter: L

Question

Lab 02: SEQUENTIAL ACCESS FILES

Write a program to read data stored in "workers.txt", which has data of 8

workers in it. Calculate the gross pay for each worker (gross pay = hourly rate *

number of work hours). Display worker ID and the gross pay of each worker on

computer screen.

INPUT

EXPECTED OUTPUT

No keyboard input, but the following data stored in the file "workers.txt" should be read into the program:

1001 10.5 20

1002 11 10.5

1003 10 16

1004 10 20

1005 12 15

1006 11.5 18

1007 10.5 12

1008 10 15.5

Worker ID: 1001 Gross pay: 210

Worker ID: 1002 Gross pay: 115.5

Worker ID: 1003 Gross pay: 160

Worker ID: 1004 Gross pay: 200

Worker ID: 1005 Gross pay: 180

Worker ID: 1006 Gross pay: 207

Worker ID: 1007 Gross pay: 126

Worker ID: 1008 Gross pay: 155


INPUT

EXPECTED OUTPUT

No keyboard input, but the following data stored in the file "workers.txt" should be read into the program:

1001 10.5 20

1002 11 10.5

1003 10 16

1004 10 20

1005 12 15

1006 11.5 18

1007 10.5 12

1008 10 15.5

Worker ID: 1001 Gross pay: 210

Worker ID: 1002 Gross pay: 115.5

Worker ID: 1003 Gross pay: 160

Worker ID: 1004 Gross pay: 200

Worker ID: 1005 Gross pay: 180

Worker ID: 1006 Gross pay: 207

Worker ID: 1007 Gross pay: 126

Worker ID: 1008 Gross pay: 155

Explanation / Answer

please rate - thanks


any questions ask


#include <iostream>
#include <fstream>
using namespace std;
int main()
{int id,i;
double rate,pay,hours;
ifstream input;
input.open("workers.txt", ios::in);       
if(input.fail())           
   { cout<<"input file did not open please check it ";
   system("pause");
   return 1;
   }
   for(i=0;i<8;i++)
   {input>>id>>rate>>hours;
    pay=rate*hours;
     cout<<"Worker ID: "<<id<<" Gross pay: "<<pay<<endl;
     }
input.close();
system("pause");
return 0;
}