You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

255 lines
6.0 KiB

6 years ago
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LEN 20 /* ְ<><D6B0><EFBFBD>ź<EFBFBD><C5BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define N 200 /* <20><><EFBFBD><EFBFBD>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*/
struct info /* <20><><EFBFBD><EFBFBD>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><E1B9B9> */
{
char jobnum[LEN+1]; /* ְ<><D6B0><EFBFBD><EFBFBD> */
char name[LEN+1]; /* <20><><EFBFBD><EFBFBD> */
char sex[3]; /* <20>Ա<EFBFBD> */
int age; /* <20><><EFBFBD><EFBFBD> */
char edu[LEN+1]; /* ѧ<><D1A7> */
int sal; /* <20><><EFBFBD><EFBFBD> */
char add[30]; /* <20><>ͥ<EFBFBD><CDA5>ַ */
char tel[LEN+1]; /* <20><EFBFBD><E7BBB0><EFBFBD><EFBFBD> */
}sta[N];
int k=1,m,n; /* <20><><EFBFBD><EFBFBD>ȫ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD> */
void readfile(); /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
void seek();
void insert();
void modify();
void del();
void display();
void save();
void menu();
int main()
{
while(k)
menu();
system("pause");
return 0;
}
void readfile() /* ¼<><C2BC><EFBFBD><EFBFBD>Ϣ */
{
FILE *fp;
int i=0;
if ((fp=fopen("staff.txt","r"))==NULL)
{ printf("Open file error! Press any key to exit!");
system("pause");
exit(0);
}
while(fscanf(fp,"%s %s %s %d %s %d %s %s",sta[i].jobnum,sta[i].name,sta[i].sex,&sta[i].age,sta[i].edu,&sta[i].sal,sta[i].add,sta[i].tel)==8)
{ i++;
i=i;
}
fclose(fp);
n=i;
printf("¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD>\n");
}
void seek()
{ int i,item,flag; /* item-ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD>ţ<EFBFBD>flag-<2D>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD> */
char s1[21]; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ռ<EFBFBD> */
printf("------------------\n");
printf("1.<2E><>ְ<EFBFBD><D6B0><EFBFBD>Ų<EFBFBD>ѯ\n");
printf("2.<2E><>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>ѯ\n");
printf("3.<2E>˳<EFBFBD><CBB3><EFBFBD><EFBFBD>˵<EFBFBD>\n");
printf("------------------\n");
while(1)
{ printf("<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD>Ӳ˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
scanf("%d",&item);
flag=0;
switch(item)
{
case 1:
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
scanf("%s",s1);
printf("ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t<EFBFBD>Ա<EFBFBD>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\tѧ<EFBFBD><EFBFBD>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t<EFBFBD><EFBFBD>ַ\t\t<EFBFBD>\n");
for(i=0;i<n;i++)
if(strcmp(sta[i].jobnum,s1)==0)
{ flag=1;
printf("%s\t%s\t%s\t%d\t%s\t%d\t%s\t%s\n",sta[i].jobnum,sta[i].name,sta[i].sex,sta[i].age,sta[i].edu,sta[i].sal,sta[i].add,sta[i].tel);
}
if(flag==0)
printf("<EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD>Ų<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>\n");
break;
case 2:
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>:\n");
scanf("%s",s1);
printf("ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t<EFBFBD>Ա<EFBFBD>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\tѧ<EFBFBD><EFBFBD>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t<EFBFBD><EFBFBD>ַ\t\t<EFBFBD>\n");
for(i=0;i<n;i++)
if(strcmp(sta[i].edu,s1)==0)
{ flag=1;
printf("%s\t%s\t%s\t%d\t%s\t%d\t%s\t%s\n",sta[i].jobnum,sta[i].name,sta[i].sex,sta[i].age,sta[i].edu,sta[i].sal,sta[i].add,sta[i].tel);
}
if(flag==0)
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڸ<EFBFBD>ѧ<EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n"); break;
case 3:
return;
default:
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1-3֮<33><D6AE>ѡ<EFBFBD><D1A1>\n");
}
}
}
void insert() /*¼<><C2BC><EFBFBD><EFBFBD>Ϣ*/
{ int i=n,j,flag;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
scanf("%d",&m);
do
{ flag=1;
while(flag)
{ flag=0;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %d <20><>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD>:\n",i+1);
scanf("%s",sta[i].jobnum);
for(j=0;j<i;j++)
if(strcmp(sta[i].jobnum,sta[j].jobnum)==0)
{ printf("<EFBFBD><EFBFBD><EFBFBD>иù<EFBFBD><EFBFBD>ţ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD>!\n");
flag=1;
break; /*<2A><><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD><CBB3>ò<EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>ٶ<EFBFBD>*/
}
}
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %d <20><>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n",i+1);
scanf("%s",sta[i].name);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %d <20><>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD>:\n",i+1);
scanf("%s",sta[i].sex);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %d <20><>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n",i+1);
scanf("%d",&sta[i].age);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %d <20><>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7>:\n",i+1);
scanf("%s",sta[i].edu);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %d <20><>ְ<EFBFBD><D6B0><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD>:\n",i+1);
scanf("%d",&sta[i].sal);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %d <20><>ְ<EFBFBD><D6B0><EFBFBD>ĵ<EFBFBD>ַ:\n",i+1);
scanf("%s",sta[i].add);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> %d <20><>ְ<EFBFBD><D6B0><EFBFBD>ĵ绰:\n",i+1);
scanf("%s",sta[i].tel);
if(flag==0)
{ i=i;
i++;
}
}while(i<n+m);
n+=m;
printf("¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD>\n\n");
}
void modify() /*<2A>޸<EFBFBD><DEB8><EFBFBD>Ϣ*/
{ int i,item,num;
char sex1[3],s1[LEN+1],s2[LEN+1];
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҪҪ<EFBFBD>޸ĵ<EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
scanf("%s",s1);
for(i=0;i<n;i++)
if(strcmp(sta[i].jobnum,s1)==0)
num=i;
printf("------------------\n");
printf("1.<2E>޸<EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>\n");
printf("2.<2E>޸<EFBFBD><DEB8>Ա<EFBFBD>\n");
printf("3.<2E>޸<EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>\n");
printf("4.<2E>޸<EFBFBD>ѧ<EFBFBD><D1A7>\n");
printf("5.<2E>޸Ĺ<DEB8><C4B9><EFBFBD>\n");
printf("6.<2E>޸ĵ<DEB8>ַ\n");
printf("7.<2E>޸ĵ绰\n");
printf("8.<2E>˳<EFBFBD><CBB3><EFBFBD><EFBFBD>˵<EFBFBD>\n");
printf("------------------\n");
while(1)
{ printf("<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD>Ӳ˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
scanf("%d",&item);
switch(item)
{
case 1:
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
scanf("%s",s2);
strcpy(sta[num].name,s2); break;
case 2:
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><EFBFBD>Ա<EFBFBD>:\n");
scanf("%s",sex1);
strcpy(sta[num].sex,sex1); break;
case 3:
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
scanf("%d",&sta[num].age);break;
case 4:
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ѧ<EFBFBD><EFBFBD>:\n");
scanf("%s",s2);
strcpy(sta[num].edu,s2); break;
case 5:
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µĹ<EFBFBD><EFBFBD><EFBFBD>:\n");
scanf("%d",&sta[num].sal); break;
case 6:
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µĵ<EFBFBD>ַ:\n");
scanf("%s",s2);
strcpy(sta[num].add,s2);break;
case 7:
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µĵ绰<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
scanf("%s",s2);
strcpy(sta[num].tel,s2); break;
case 8:
return;
default:
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1-8֮<38><D6AE>ѡ<EFBFBD><D1A1>\n");
}
}
}
void del() /* ɾ<><C9BE><EFBFBD><EFBFBD>Ϣ */
{ int i,j,flag=0;
char s1[LEN+1];
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫɾ<EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
scanf("%s",s1);
for(i=0;i<n;i++)
if(strcmp(sta[i].jobnum,s1)==0)
{ flag=1;
for(j=i;j<n-1;j++)
sta[j]=sta[j+1];
}
if(flag==0)
printf("<EFBFBD><EFBFBD>ְ<EFBFBD><EFBFBD><EFBFBD>Ų<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>\n");
if(flag==1)
{ printf("ɾ<EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD>\n");
n--;
}
}
void display()
{ int i;
printf("ְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t<EFBFBD>Ա<EFBFBD>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\tѧ<EFBFBD><EFBFBD>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>\t<EFBFBD><EFBFBD>ַ\t\t<EFBFBD>\n");
for(i=0;i<n;i++)
{
printf("%s\t%s\t%s\t%d\t%s\t%d\t%s\t%s\n",sta[i].jobnum,sta[i].name,sta[i].sex,sta[i].age,sta[i].edu,sta[i].sal,sta[i].add,sta[i].tel);
}
}
void save() /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ */
{ int i,flag=0;
FILE *fp;
fp=fopen("staff.txt","w");
for(i=0;i<n;i++)
{ fprintf(fp,"%s %s %s %d %s %d %s %s\n",sta[i].jobnum,sta[i].name,sta[i].sex,sta[i].age,sta[i].edu,sta[i].sal,sta[i].add,sta[i].tel);
}
fclose(fp);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD>");
}
void menu() /* <20><><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD> */
{ int num;
printf(" \n\nְ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ\n\n");
printf("*****ϵͳ<CFB5><CDB3><EFBFBD>ܲ˵<DCB2>*****\n");
printf("----------------------\n");
printf("1.<2E><><EFBFBD><EFBFBD>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD>Ϣ\n");
printf("2.<2E><>ѯְ<D1AF><D6B0><EFBFBD><EFBFBD>Ϣ\n");
printf("3.¼<><C2BC>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD>Ϣ\n");
printf("4.<2E>޸<EFBFBD>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD>Ϣ\n");
printf("5.<2E><>ְ<EFBFBD><D6B0><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD>Ϣ\n");
printf("6.<2E><>ʾ<EFBFBD><CABE>ǰ<EFBFBD><C7B0>Ϣ\n");
printf("7.<2E><><EFBFBD>浱ǰְ<C7B0><D6B0><EFBFBD><EFBFBD>Ϣ\n");
printf("8.<2E>˳<EFBFBD>ϵͳ\n");
printf("----------------------\n");
printf("<EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:");
scanf("%d",&num);
switch(num)
{
case 1:readfile();break;
case 2:seek();break;
case 3:insert();break;
case 4:modify();break;
case 5:del();break;
case 6:display();break;
case 7:save();break;
case 8:k=0;break;
default:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1-8֮<38><D6AE>ѡ<EFBFBD><D1A1>\n");
}
}