NOTE: THE ANSWER LISTED IN CHEGG TEXTBOOK SOLUTIONS IS INCORRECT Construct a sol
ID: 3682981 • Letter: N
Question
NOTE: THE ANSWER LISTED IN CHEGG TEXTBOOK SOLUTIONS IS INCORRECT
Construct a solution algorithm for the following programming problems. Your solution should contain: a defining diagram a list of control structures required a pseudocode algorithm a desk check of the algorithm. An employee file contains records that show an employee's number, name, job code and pay code. The job codes and pay codes are three-digit codes that refer to corresponding job descriptions and pay rates, as in the following tables: Your program is to read the employee file, use the job code to retrieve the job description from the job table, use the pay code to retrieve the pay rate from the pay rate table, and print for each record the employee's number, name, job description and pay rate. At the end of the report, print the total number of employees.Explanation / Answer
Define DML methods
display();
create();
update();
Accept Input
32. printf(" Enter your choice : ");
If- Case
case 1:
Open the File to read the data set
Invoke method create()
case 2:
Open the File to display the data set
Invoke method create()
case 3:
Open the File to Update the data set
Invoke method create()
case 4:
exit(0);
To create an employee record
Invoke Method Create()
emp1 = (struct emp *)malloc(sizeof(struct emp));
emp1->name = (char *)malloc((size)*(sizeof(char)));
printf("Enter name of employee : ");
scanf(" %[^ ]s", emp1->name);
printf("Enter emp id : ");
scanf(" %d", &emp1->id);
fwrite(&emp1->id, sizeof(emp1->id), 1, fp);
fwrite(emp1->name, size, 1, fp);
count++; // count to number of entries of records
fclose(fp)
Display the records in the file
Invoke Method display()
emp3=(struct emp *)malloc(1*sizeof(struct emp));
emp3->name=(char *)malloc(size*sizeof(char));
int i = 1;
if (fp1 == NULL)
printf(" File not opened for reading");
while (i <= count
fread(&emp3->id, sizeof(emp3->id), 1, fp1);
fread(emp3->name, size, 1, fp1); i++;
fclose(fp1); free(emp3->name); free(emp3);
update()v if (fp1 == NULL)
“ File cannot Open “
return;
Input EMPID for Update
emp3 = (struct emp *)malloc(1*sizeof(struct emp));
emp3->name=(char *)malloc(size*sizeof(char));
while(i<=count)
fread(&emp3->id, sizeof(emp3->id), 1, fp1);
fread(emp3->name,size,1,fp1);
if (id == emp3->id)
Input : “Enter EMP Name”
fseek(fp1, -204L, SEEK_CUR);
fwrite(&emp3->id, sizeof(emp3->id), 1, fp1);
fwrite(s, size, 1, fp1);
flag = 1; i++;
if (flag != 1)
Print : ("No employee record found"); fclose(fp1);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.