Professional Documents
Culture Documents
h>
#include<stdlib.h>
char *code;
char *name;
double salary;
double allowance;
}employee;
void bubblesort(employee*,int);
int equals(char*,char*);
int main()
employee *e=NULL;
while(stop)
scanf("%d",&choice);
switch(choice)
e[n].name=calloc(20,sizeof(char));
printf("code: ");
scanf("%s",e[n].code);
printf("name: ");
scanf("%s",e[n].name);
printf("salary: ");
scanf("%lf",&e[n].salary);
printf("allowance: ");
scanf("%lf",&e[n].allowance);
break;
case 2:
if(n==0)
break;
scanf("%s",c);
for(int i=0;i<n;i++)
if(equals(e[i].code,c))
for(int j=i;j<n-1;j++)
e[j]=e[j+1];
break;
case 3:
if(n==0)
break;
scanf("%s",c);
for(int i=0;i<8;i++)
if(c[i]=='\n')
c[i]='\0';
for(int i=0;i<n;i++)
break;
case 4:
if(n==0)
break;
bubblesort(e,n);
for(int i=0;i<n;i++)
printf("code: %s\tname: %s\tsalary: %lf\tallowance: %lf\
n",e[i].code,e[i].name,e[i].salary,e[i].allowance);
break;
case 5:
stop=0;
break;
default:
break;
return 0;
int swap=1;
employee aux;
while(swap)
swap=0;
for(int i=0;i<n-1;i++)
for(int j=i;j<n;j++)
if(e[j].salary>e[i].salary)
aux=e[j];
e[j]=e[i];
e[i]=aux;
swap=1;
return;