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

In C Programming: 2. (4pt) Suppose we have an employee data file (say emp.txt) c

ID: 665552 • Letter: I

Question

In C Programming:

2. (4pt) Suppose we have an employee data file (say emp.txt) containing the followings in each line per employee: employee ID, how many days he/she worked, and how many hours he/she worked in each day. Complete the following program that can read emp.txt file and print out the employee ID and total number of hours for each employee into an output file (say out.txt). For example, here is a sample emp. txt file with two employees and the expected out. txt file (an actual file may have more lines or days, so your program should be general enough to work with other files containing different number of employees or days):

Explanation / Answer

here is the program :

#include <studio.h>
#include <fstream.h>
void main()
{

FILE *infile,*outfile;
char a;

int array[15][15];

int y;
int x;
int emp1 = 11;
int emp2 = 13;
int row1[0] = 5 ;
int row1[1] = 8;
int row1[3] = 2;
int row1[4] =7;
   
int row2[0] = 2;
   int row2[1] = 4;
   int row2[2] = 4;
int row2[3] = 3;
int row2[4] = 5;
int row2[5] = 4;
   int row2[6] 3;
    int row2[7] = 5;
int row2[8] = 2;
   int row2[9] = 4;
   int assignments;
   int emp1tot;
   int emp2tot;

infile = fopen("emp.txt", "r");

for(y = 0; y <15; y++) {
    for(x = 0; x <15; x++) {
      fscanf(infile, "%d", &(array[x][y]));
    }
    fscanf(infile, " ");
}
fclose (infile);
for(y = 0; y < 15; y++) {
    for(x = 0; x < 15; x++) {
      printf("%d ", array[x][y]);
    }
    printf(" ");
}
return 0;
}

  
   if (infile == NULL) {
      puts("cannot open this file");
      exit(1);
   }

emp1tot = row1[0] + row1[1] + row1[2] + row1[3] +row1[4];
emp2tot = row2[0]+row2[1]+row2[2]+row2[3]+row2[4]+row2[5]+row2[6]+row2[7]+row2[8]+row2[9]


outfile = fopen("out.txt", "w");
   if (outfile == NULL) {
      puts("Not able to open this file");
      fclose(infile);
      exit(1);
   }
outfile = emp1tot;
outfile=emp2tot;

   do {
      a = fgetc(infile);
   b= fgetc(outfile);
      fputc(a, outfile);
   fputc(b,outfile);
   } while (a != EOF);

   fcloseall();
   getch();