Implement an employee salary management system using C language, employee inform
ID: 3561615 • Letter: I
Question
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.
=============================
#include <stdio.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);
while(fread(&emp,recsize,1,fp)==1)
{
if(strcmp(emp.id,id)!=0)
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(strcmp(emp.id,id)==0)
{
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 %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
#include #include #include #define NUM_EMPLOYEE 10 int main(int argc, char *argv[]){ //initialise Salary of each employee int Salary[NUM_EMPLOYEE][2]={ {2300,0}, {3400,0}, {3200,0}, {1200,0}, {3450,0}, {3800,0}, {3900,0}, {2680,0}, {3340,0}, {3000,0} }; int lCount=0,gCount=0,i=0; for(i=0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.