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.

392 lines
8.3 KiB

6 years ago
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student
{
char num[20];char name[20];char id[10];char sex[4];int age;char tele[15];
}student[500],student1;
void menu();
void type_in();
void baocun(int);
void scan();
void del();
void search();
void search_name();
void change();
void add();
void menu()
{
printf("\n");
printf(" 1.¼<><C2BC>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ\n");
printf(" 2.<2E><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ\n");
printf(" 3.<2E><>ѯѧ<D1AF><D1A7><EFBFBD><EFBFBD>Ϣ\n");
printf(" 4.ɾ<><C9BE>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ\n");
printf(" 5.<2E>޸<EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ\n");
printf(" 6.<2E><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ\n");
printf(" 7.<2E>˳<EFBFBD>\n");
printf("\n");
}
/********************************************************************************************/
int main()
{
int n,f;
while(1)
{
do
{
menu();
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(1-7):\n");
scanf("%d",&n);
if(n>=1&&n<=7)
{
f=1;
break;
}
else
{
f=0;
printf("<EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
}while(f==0);
switch(n)
{
case 1:printf(" ¼<><C2BC>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ\n\n"); type_in(); break;
case 2:printf(" <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ\n\n"); system("cls"); scan(); break;
case 3:printf(" <20><>ѯѧ<D1AF><D1A7><EFBFBD><EFBFBD>Ϣ\n\n"); system("cls"); search(); break;
case 4:printf(" ɾ<><C9BE>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ\n\n"); system("cls"); del(); break;
case 5:printf(" <20>޸<EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ\n\n"); system("cls"); change(); break;
case 6:printf(" <20><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ\n\n"); system("sls"); add(); break;
case 7:goto loop;
}
}
loop:
system("cls");
return 0;
}
/***********************************************************************************/
void type_in()
{
int i,m;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(1--500):\n");
scanf("%d",&m);
for (i=0;i<m;i++)
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD>ţ<EFBFBD> ");
scanf("%s",student[i].num);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ");
scanf("%s",student[i].name);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ");
scanf("%d",&student[i].age);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>绰: ");
scanf("%s",student[i].tele);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ");
scanf("%s",&student[i].id);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD>: ");
scanf("%s",&student[i].sex);
getchar();system("cls");
printf("\n");
}
baocun(m);
}
void baocun(int m)
{
int i;
FILE *fp;
if ((fp=fopen("D:\\student_list.txt","wb"))==NULL)
{
printf ("<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><EFBFBD><EFBFBD>\n");
exit(0);
}
for (i=0;i<m;i++)
if (fwrite(&student[i],sizeof(struct student),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
int fun()
{
FILE*fp;
int i=0;
if((fp=fopen("D:\\student_list.txt","rb"))==NULL)
{
printf ("cannot open file\n");
exit(0);
}
else
{
do
{
fread(&student[i],sizeof(struct student),1,fp);
i++;
}
while(feof(fp)==0);
}
fclose(fp);
return(i-1);
}
void scan()
{
int i;
int m=fun();
printf("\nѧ<EFBFBD><EFBFBD> \t<EFBFBD><EFBFBD><EFBFBD><EFBFBD> \t<EFBFBD><EFBFBD><EFBFBD><EFBFBD> \t<EFBFBD>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤ \t<EFBFBD>Ա<EFBFBD> \n");
for(i=0;i<m;i++)
printf("%s \t%s \t%d \t%s \t%s \t%s \n",student[i].num,student[i].name,student[i].age,student[i].tele,student[i].id,student[i].sex);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\n");
getchar();
getchar();system("cls");
}
void del()
{
int m=fun();
int i,j,n,t,f;
char name1[10];
printf("\n ԭ<><D4AD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ:\n");
scan();
printf("\n");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
scanf("%s",name1);
for(f=1,i=0;f&&i<m;i++)
{
if(strcmp(student[i].name,name1)==0)
{
printf("\n<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD>ԭʼ<EFBFBD><EFBFBD>¼Ϊ<EFBFBD><EFBFBD>\n");
printf("\nѧ<EFBFBD><EFBFBD> \t<EFBFBD><EFBFBD><EFBFBD><EFBFBD> \t<EFBFBD><EFBFBD><EFBFBD><EFBFBD> \t<EFBFBD>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤ \t<EFBFBD>Ա<EFBFBD> \n");
printf("%s \t%s \t%d \t%s \t%s \t%s \n",student[i].num,student[i].name,student[i].age,student[i].tele,student[i].id,student[i].sex);
printf("\nȷʵҪɾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>밴1,<2C><>ɾ<EFBFBD><C9BE><EFBFBD>밴0\n");
scanf("%d",&n);
if(n==1)
{
for(j=i;j<m-1;j++)
{
student[j]=student[j+1];
}
f=0;
}
}
}
if(!f)
m=m-1;
else
printf("\n<EFBFBD><EFBFBD><EFBFBD>޴<EFBFBD><EFBFBD><EFBFBD>!\n");
printf("\n <20><><EFBFBD><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ:\n");
baocun(m);
scan();
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD>밴1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɾ<EFBFBD><EFBFBD><EFBFBD>밴0\n");
scanf("%d",&t);
switch(t)
{
case 1:del();break;
case 0:break;
default :break;
}system("cls");
}
void search()
{
int t,f;
do
{
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD>밴1; <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2\n");
scanf("%d",&t);
if(t>=1&&t<=2)
{
f=1;
break;
}
else
{
f=0;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>!");
}
}while(f==0);system("cls");
while(f==1)
{
switch(t)
{
case 1:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ\n");search_name();break;
case 2:main();break;
default:break;
}
system("cls");
}
}
/***********************************************************************************/
void search_name()/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Һ<EFBFBD><D2BA><EFBFBD>*/
{
char name1[10];
int i,t;
int m=fun();
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
scanf("%s",name1);
for(i=0;i<m;i++)
if(strcmp(name1,student[i].name)==0)
{
printf("\n<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼Ϊ<EFBFBD><EFBFBD>\n");
printf("\nѧ<EFBFBD><EFBFBD> \t<EFBFBD><EFBFBD><EFBFBD><EFBFBD> \t<EFBFBD><EFBFBD><EFBFBD><EFBFBD> \t<EFBFBD>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤ \t<EFBFBD>Ա<EFBFBD> \n");
printf("%s \t%s \t%d \t%s \t%s \t%s \n",student[i].num,student[i].name,student[i].age,student[i].tele,student[i].id,student[i].sex);
break;
}
if(i==m)
printf("\nδ<EFBFBD>ҵ<EFBFBD>\n");
printf("\n");
printf("<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>밴1,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD>밴2\n");
scanf("%d",&t);
switch(t)
{
case 1:search();break;
case 2: break;
default:break;
}
}
/*************************************************************************************/
void search_num()
{
char num1[10];
int i,t;
int m=fun();
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD>ѧ<EFBFBD><EFBFBD>:\n");
scanf("%s",num1);
for(i=0;i<m;i++)
if(student[i].num==0)
{
printf("\n<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼Ϊ<EFBFBD><EFBFBD>\n");
printf("\nѧ<EFBFBD><EFBFBD> \t<EFBFBD><EFBFBD><EFBFBD><EFBFBD> \t<EFBFBD><EFBFBD><EFBFBD><EFBFBD> \t<EFBFBD>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤ \t<EFBFBD>Ա<EFBFBD> \n");
printf("%s \t%s \t%d \t%s \t%s \t%s \n",student[i].num,student[i].name,student[i].age,student[i].tele,student[i].id,student[i].sex);
break;
}
if(i==m)
printf("\nδ<EFBFBD>ҵ<EFBFBD>\n");
printf("\n");
printf("<EFBFBD><EFBFBD><EFBFBD>ز<EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>밴1,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѯѧ<D1AF><D1A7><EFBFBD>밴2\n");
scanf("%d",&t);
switch(t)
{
case 1:search();break;
case 2: break;
default:break;
}
}
/***************************************************************************************/
void change()
{
char num[20];
char name[20];
char id[10];
char sex[4];
long long int age;
char tele[15];
int b,c,i,n,t,f;
int m=fun();
printf("\n ԭ<><D4AD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD><EFBFBD>Ϣ:\n");
scan();
printf("\n");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>޸ĵ<EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
scanf("%s",name);
for(f=1,i=0;f&&i<m;i++)
{
if(strcmp(student[i].name,name)==0)
{
printf("\n<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˣ<EFBFBD>ԭʼ<EFBFBD><EFBFBD>¼Ϊ<EFBFBD><EFBFBD>\n");
printf("\nѧ<EFBFBD><EFBFBD> \t<EFBFBD><EFBFBD><EFBFBD><EFBFBD> \t<EFBFBD><EFBFBD><EFBFBD><EFBFBD> \t<EFBFBD>\t<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤ \t<EFBFBD>Ա<EFBFBD> \n");
printf("%s \t%s \t%d \t%s \t%s \t%s \n",student[i].num,student[i].name,student[i].age,student[i].tele,student[i].id,student[i].sex);
printf("\nȷʵҪ<EFBFBD>޸Ĵ<EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>밴1 ; <20><><EFBFBD>޸<EFBFBD><DEB8>밴0\n");
scanf("%d",&n);
if(n==1)
{
printf("\n<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸ĵ<EFBFBD>ѡ<EFBFBD><EFBFBD>\n 1.ѧ<><D1A7> 2.<2E><><EFBFBD><EFBFBD> 3.<2E><><EFBFBD><EFBFBD> 4.<2E>绰 5.<2E><><EFBFBD><EFBFBD>֤ 6.<2E>Ա<EFBFBD>\n");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸ĵ<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
scanf("%d",&c);
if(c>6||c<1)
printf("\nѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD>!\n");
}
f=0;
}
}
if(f==1)
printf("\nδ<EFBFBD>ҵ<EFBFBD>\n");
do
{
switch(c)
{
case 1:printf("ѧ<EFBFBD>Ÿ<EFBFBD>Ϊ: ");
scanf("%s",num);
strcpy(student[i-1].num,num);
break;
case 2:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ: ");
scanf("%s",name);
strcpy(student[i-1].name,name);
break;
case 3:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ: ");
scanf("%lld",&age);
student[i-1].age=age;
break;
case 4:printf("<EFBFBD><EFBFBD><EFBFBD>Ϊ: ");
scanf("%s",tele);
strcpy(student[i-1].tele,tele);
break;
case 5:printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD>Ÿ<EFBFBD>Ϊ: ");
scanf("%s",id);
strcpy(student[i-1].id,id);
break;
case 6:printf("<EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD>Ϊ: ");
scanf("%s",sex);
strcpy(student[i-1].sex,sex);
break;
}
printf("\n");
printf("\n<EFBFBD>Ƿ<EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸ĵ<EFBFBD><EFBFBD><EFBFBD>Ϣ?\n <20><> <20>밴1 ; \n<EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD> <20>밴2: \n");
scanf("%d",&b);
}
while(b==2);
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸ĺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ:\n");
printf("\n");
baocun(m);
scan();
printf("\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><EFBFBD>밴1<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><EFBFBD>밴0\n");
scanf("%d",&t);
switch(t)
{
case 1:change();break;
case 0:break;
default :break;
}system("cls");
}
void add()
{
int n=fun();
int i,m;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(1--500):\n");
scanf("%d",&m);
for (i=n;i<m+n;i++)
{
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD>ţ<EFBFBD> ");
scanf("%s",student[i].num);
printf("\n");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: ");
scanf("%s",student[i].name);
getchar();
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
scanf("%lld",&student[i].age);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>绰: ");
scanf("%s",student[i].tele);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤: ");
scanf("%s",student[i].id);
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD>: ");
scanf("%s",student[i].sex);
getchar();system("cls");
printf("\n");
}
baocun(m+n);system("cls");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɡ<EFBFBD>\n<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϢΪ<EFBFBD><EFBFBD>\n");
scan();
}