My question is does the program I have written followed the requirements given i
ID: 3561780 • Letter: M
Question
My question is does the program I have written followed the requirements given in the question below?
Please if didnt follow them ..Correct them and tell me what you have corrected ..Also what does rewind() mean ?
Implement an employee salary management system using C language, employee information includes: employee number, name, date, salary. (employee number is unique).
Question 1: salary input: input employee salary.
Question 2: salary enquiry: browse employee salary by name and date.
Question 3: employee list: output employee by annual salary.
Question 4: employee delete: delete an employee record by user input.
=========================================================
//Error Free Program
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct Employee
{
char fname[20];
char lname[20];
//char sub_taken[20];
//char last_edu[20];
// char join_date[20];
int id;
// int age;
float bsal;
}Employee;
int main(void)
{
int id;
FILE *fp, *ft;
char another, choice;
Employee emp;
char fname[20];
char lname[20];
long int recsize;
fp=fopen("EMP.DAT", "rb+");
if(fp==NULL)
{
fp=fopen("EMP.DAT", "wb+");
if(fp==NULL)
{
printf("Cant open the file");
//exit();
}
}
recsize=sizeof(emp);
while(1)
{
printf("Add Records(1) ");
//printf(" ");
printf("Delete Records(2) ");
printf("Modify Records(3) ");
printf("List Records(4) ");
printf("Exit(5) ");
printf("Enter your choice ");
fflush(stdin);
scanf("%c",&choice);
switch(choice)
{
case'1':
fseek(fp,0,SEEK_END);
another='Y';
while(another=='Y'||another=='y')
{
printf("Enter the first Name and the last Name ");
scanf("%s",&emp.fname);
//printf("Enter the Age ");
// scanf("%s",&emp.age);
printf("Enter the basic salary ");
scanf("%s",&emp.bsal);
// printf("Enter Joining Date ");
//scanf("%s",&emp.join_date);
printf("Enter the ID NO. ");
scanf("%d",&emp.id);
//printf("Enter the last education ");
//scanf("%s",&emp.last_edu);
//printf("Enter the subject taken ");
//scanf("%s",&emp.sub_taken);
fwrite(&emp,recsize,1,fp);
printf("Add another Record (Y/N) ");
fflush(stdin);
another=getchar();
}
break;
case '2':
another='Y';
while(another=='Y'||another=='Y')
{
printf("Enter the ID of the employee to be deleted: ");
scanf("%d",&id);
ft=fopen("TEMP.DAT","wb");
rewind(fp);
char* id_string;
while(fread(&emp,recsize,1,fp)==1)
{
if(emp.id!=id)
fwrite(&emp,recsize,1,ft);
}
fclose(fp);
fclose(ft);
remove("EMP.DAT");
rename("TEMP.DAT","EMP.DAT");
fp=fopen("EMP.DAT","rb+");
printf("Delete another Record (Y/N): ");
fflush(stdin);
another=getchar();
}
break;
case'3':
another='Y';
while(another=='Y'||another=='y')
{
printf("Enter the name of employee to modify: ");
scanf("%s",emp.fname);
rewind(fp);
while(fread(&emp,recsize,1,fp)==1)
{
if(emp.id==id)
{
printf("Enter new First name");
scanf("%s",&emp.fname);
printf("Enter new Last name");
scanf("%s",&emp.lname);
//printf("Enter Age");
//scanf("%d",&emp.age);
printf("Enter basic salary");
scanf("%f",&emp.bsal);
// printf("Enter joining date");
//scanf("%s",&emp.join_date);
//printf("Enter subject Taken ");
//scanf("%s",&emp.sub_taken);
//printf("Enter last education");
// scanf("%s",&emp.last_edu );
fseek(fp,-recsize,SEEK_CUR);
fwrite(&emp,recsize,1,fp);
break;
}
}
printf("Do you wanna modify other records(Y/N)");
}
break;
case'4':
rewind(fp);
while(fread(&emp,recsize,1,fp)==1)
printf("%s",emp.fname);
printf(" ");
printf("%s",emp.lname);
printf(" ");
//printf("%d",emp.age);
printf(" ");
printf("%g",emp.bsal);
printf(" ");
// printf("%s %s %d %g",emp.fname,emp.lname,emp.age,emp.bsal,emp.join_date,emp.last_edu ,emp.sub_taken );
break;
case'5':
fclose(fp);
//exit();
}
}
}
Explanation / Answer
whatever you coded will not work.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.