1、#include#include#include#include#define len sizeof(struct student)FILE *fp;struct student long num; char name15;int age; char sex3;char chushen10;char dizhi20;char phone11;char email20; struct student *next;void menu() printf(=学生信息管理系统=nn); printf( 1、录入学生信息n); printf( 2、浏览学生信息n); printf( 3、查询学生信息n);
2、 printf( 4、删除学生信息n);printf( 5、插入学生信息n); printf( 6、修改学生信息n);printf( 7、排序学生信息n);printf( 8、退出管理系统n); printf(=n);struct student *creat() /录入学生信息int n;struct student *head; struct student *p1,*p2;n=0; p1=p2=(struct student *) malloc(len); scanf(%dt%dt%st%st%st%st%st%s,&p1-num,&p1-age,p1-name,p1-sex,p1-ch
3、ushen,p1-dizhi,p1-phone,p1-email); head=NULL; while(p1-num!=0) n=n+1;if(n=1) head=p1;else p2-next=p1;p2=p1;p1=(struct student *)malloc(len);scanf(%dt%dt%st%st%st%st%st%s,&p1-num,&p1-age,p1-name,p1-sex,p1-chushen,p1-dizhi,p1-phone,p1-email); p2-next=NULL; return(head);void insert(struct student *head
4、) /插入学生信息 int search_num; struct student *p,*q,*s; p=head; printf(在哪个学生前插入 请输入学号:n); scanf(%d,&search_num); while(p!=NULL)&(p-num!=search_num) q=p; p=p-next; s=(struct student *)malloc(len); q-next=s; system(cls); printf(请输入学生信息:n); printf(学号t年龄t姓名t性别t出生t地址t电话te-mailn); scanf(%dt%dt%st%st%st%st%st%s
5、,&s-num,&s-age,s-name,s-sex,s-chushen,s-dizhi,s-phone,s-email);s-next=p;void printList(struct student *head) /浏览全部学生信息 struct student *p; p=head; if(head=NULL) printf(没有学生信息!n); else do fread(p,len,1,fp); printf(%dt%dt%st%st%st%st%st%sn,p-num,p-age,p-name,p-sex,p-chushen,p-dizhi,p-phone,p-email); p=
6、p-next; while(p!=NULL); void findList_num(struct student *head,long search_num) /按学号查找 struct student *p; p=head; while(p!=NULL)&(p-num!=search_num) p=p-next; if(p!=NULL) printf(%dt%dt%st%st%st%st%st%sn,p-num,p-age,p-name,p-sex,p-chushen,p-dizhi,p-phone,p-email); else printf(没有该学生信息!n);void findList
7、_name(struct student *head,char *search_name) /按姓名查找 struct student *p; int cmp1=0,cmp=0; p=head; while(p!=NULL) if(strcmp(p-name,search_name)!=0) p=p-next; cmp+; else printf(%dt%dt%st%st%st%st%st%sn,p-num,p-age,p-name,p-sex,p-chushen,p-dizhi,p-phone,p-email); p=p-next; cmp1=1; if(cmp!=0&cmp1=0) pri
8、ntf(没有该学生信息!n); void xiugai(struct student *p1,long xiu_num) /修改学生信息struct student *p2;p2=p1;while(p2!=NULL)&(p2-num!=xiu_num)p2=p2-next; if(p2!=NULL)scanf(%dt%dt%st%st%st%st%st%s,&p2-num,&p2-age,p2-name,p2-sex,p2-chushen,p2-dizhi,p2-phone,p2-email);else printf(没有该学生信息!n); struct student *delList(st
9、ruct student *head,long del_num) / 删除学生信息 struct student *p,*q; p=head; q=head; while(p &(p-num != del_num) q=p; p=p-next; if(p=NULL) printf(无此学号!n); else if(p = head) head = p-next; free(p); else q-next = p-next; free(p); return head;void paixu(struct student *head) /按学号排序struct student *p,*f,*t;ch
10、ar ch100;int i;t=f=p=head;for(p=head;p-next!=NULL;p=p-next)for(t=head,f=t-next;t-next!=NULL;t=t-next,f=f-next)if(t-numf-num0)i=t-num;t-num=f-num;f-num=i;i=t-age;t-age=f-age;f-age=i;strcpy(ch,t-name);strcpy(t-name,f-name);strcpy(f-name,ch);strcpy(ch,t-sex);strcpy(t-sex,f-sex);strcpy(f-sex,ch);strcpy(
11、ch,t-chushen);strcpy(t-chushen,f-chushen);strcpy(f-chushen,ch);strcpy(ch,t-dizhi);strcpy(t-dizhi,f-dizhi);strcpy(f-dizhi,ch);strcpy(ch,t-phone);strcpy(t-phone,f-phone);strcpy(f-phone,ch);strcpy(ch,t-email);strcpy(t-email,f-email);strcpy(f-email,ch);/return head;void save(struct student *head) /保存为磁盘
12、文件struct student *p;if(fp=fopen(keshe,w)=NULL)printf(cannot open this filen);exit(0);p=head;while(p!=NULL)fprintf(fp,%dn,p-num);fprintf(fp,%dn,p-age);fprintf(fp,%sn,p-name);fprintf(fp,%sn,p-sex);fprintf(fp,%sn,p-chushen);fprintf(fp,%sn,p-dizhi);fprintf(fp,%sn,p-phone);fprintf(fp,%sn,p-email);p=p-nex
13、t;fclose(fp);struct student *read() /从磁盘读取文件struct student *head=NULL;struct student *p=NULL;struct student *t=NULL;int a;/fp=fopen(keshe,r);if(fp=fopen(keshe,r)=NULL)printf(cannot open this filen);exit(0);while(1)t=(struct student *)malloc(len);a=fscanf(fp,%dt%dt%st%st%st%st%st%s,&t-num,&t-age,t-na
14、me,t-sex,t-chushen,t-dizhi,t-phone,t-email);if(a=0|a=-1)return head;t-next=NULL;if(p=NULL)p=t;head=t;elsep-next=t;p=p-next;p-next=NULL;fclose(fp);void main() int code=0; struct student *pt = NULL; while(code!=8) menu(); printf(请输入上述序号进行操作:n); scanf(%d,&code);system(cls); switch(code) case 1: system(
15、cls);printf(每个学生的信息之间用Tab键分隔n); printf(=录入学生信息=n); printf(-n); printf(学号t年龄t姓名t性别t出生t地址t电话te-mailn); pt=creat();save(pt); system(cls); printf(=录入学生信息=n); printf(-n); printf(*录入学生信息成功*!n); printf(按回车键返回主菜单n); getchar(); getchar(); system(cls); ;break;case 2: system(cls); printf(=学生信息表=n); printf(-n);
16、 printf(学号t年龄t姓名t性别t出生t地址t电话te-mailn);pt=read(); printList(pt); printf(=n);printf(-n); printf(n按回车键返回主菜单n); getchar(); getchar(); system(cls); ;break; case 3: int search=0; system(cls); printf(=查询学生信息=n); printf(-n); while(search!=3) printf(1、按学号查询n2、按姓名查询n3、退出查询n); scanf(%d,&search); switch(search)
17、 case 1: long search_num; system(cls); printf(请输入学生学号n); scanf(%d,&search_num); system(cls); printf(=查询结果=n);printf(-n); printf(学号t年龄t姓名t性别t出生t地址t电话te-mailn); findList_num(read(),search_num); printf(=n);printf(-n); printf(n按回车键返回查询菜单n); getchar(); getchar(); system(cls); ;break; case 2: char search_
18、name15; system(cls); printf(请输入学生姓名n); scanf(%s,search_name); system(cls); printf(=查询结果=n);printf(-n); printf(学号t年龄t姓名t性别t出生t地址t电话te-mailn); findList_name(read(),search_name); printf(=n);printf(-n); printf(n按回车键返回查询菜单n); getchar(); getchar(); system(cls); ; system(cls); ;break; case 4: long del_num;
19、 system(cls); printf(=删除学生信息=n); printf(-n); printf(请输入要删除学生信息的学号:n); scanf(%d,&del_num); system(cls); pt=delList(read(),del_num);save(pt); printf(=删除结果=n); printf(-n); printf(学号为%d的学生信息成功删除n,del_num); printf(n按回车键返回主菜单n); getchar(); getchar(); system(cls); ;break;case 5:system(cls);printf(每个学生的信息之间
20、用Tab键分隔n); printf(=插入学生信息=n); printf(-n); insert(pt);save(pt); system(cls); printf(=插入学生信息=n); printf(-n); printf(*插入学生信息成功*!nn); printf(按回车键返回主菜单n); getchar(); getchar(); system(cls); break;case 6:long search_num; system(cls); printf(请输入要修改的学生学号:n); scanf(%d,&search_num); system(cls);printf(每个学生的信息
21、之间用Tab键分隔n); printf(=修改学生信息=n);printf(-n);printf(学号t年龄t姓名t性别t出生t地址t电话te-mailn);findList_num(read(),search_num);printf(n);printf(请输入修改信息:n);printf(学号t年龄t姓名t性别t出生t地址t电话te-mailn);pt=read(); xiugai(pt,search_num);save(pt); printf(=n);printf(-n);printf(*修改学生信息成功*!nn); printf(n按回车键返回查询菜单n); getchar(); getchar(); system(cls);break;case 7: system(cls);printf( 按学号从小到大排序 nn); printf(=学生信息表=n); printf(-n); printf(学号t年龄t姓名t性别t出生t地址t电话te-mailn);pt=read();paixu(pt); printList(pt);save(pt); printf(=n);printf(-n); printf(n按回车键返回主菜单n); getchar(); getchar(); system(cls); ;break;case 8:read();break;