资源描述:
《学生管理系统代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#include#include#includeusingnamespacestd;structstudent{intxh;charxm[20];intbj;charsex[20];chardate[20];intcj;structstudent*next;};structstudent*head,*p,*q,*s;structstudent*creat(){structstudent*p1,*head,*p2;head=p
2、1=p2=(structstudent*)malloc(sizeof(structstudent));//创建一个节点printf("====请输入学生信息====");printf("请输入学生编号:");scanf("%d",&p1->xh);while(p1->xh!=0){printf("姓名:");scanf("%s",&p1->xm);printf("性别:");scanf("%s",&p1->sex);printf("班级:");scanf("%d",&p1->bj);printf("出生日
3、期:");scanf("%s",&p1->date);printf("总分:");scanf("%d",&p1->cj);p1=(structstudent*)malloc(sizeof(structstudent));p2->next=p1;p2=p1;printf("请输入学生编号:");scanf("%d",&p1->xh);}p2->next=NULL;returnhead;}voidsave(structstudent*head)//保存链表为磁盘文件{FILE*fp;structstudent*p;if(
4、(fp=fopen("stu.dat","wb"))==NULL){printf("创建文件失败!");return;}p=head;while(p!=NULL){fprintf(fp,"%d",p->xh);fprintf(fp,"%s",p->xm);fprintf(fp,"%d",p->bj);fprintf(fp,"%s",p->sex);fprintf(fp,"%d",p->date);fprintf(fp,"%d",p->cj);p=p->next;}fputs("over",
5、fp);printf("文件保存成功!");fclose(fp);}voidsort(structstudent*head){structstudent*p,*f,*t;charch[100];inti;p=f=t=head;for(p=head;p->next!=NULL;p=p->next)//由P来控制循环次数{for(t=head,f=t->next;t->next!=NULL;t=t->next,f=f->next){if((t->xh)>(f->xh)){i=t->xh;t->xh=f->xh;f->
6、xh=i;strcpy(ch,t->xm);strcpy(t->xm,f->xm);strcpy(f->xm,ch);strcpy(ch,t->sex);strcpy(t->sex,f->sex);strcpy(f->sex,ch);i=t->bj;t->bj=f->bj;f->bj=i;i=t->cj;t->cj=f->cj;f->cj=i;strcpy(ch,t->date);strcpy(t->date,f->date);strcpy(f->date,ch);}}}for(p=head;p->next!=NUL
7、L;p=p->next){printf("%d%s%d%d%s%s",p->xh,p->xm,p->bj,p->cj,p->date,p->sex);}printf("排序成功!");}voidinsert(structstudent*head,intxh,charxm[],intbj,charsex[],chardate[],intcj){p=head;s=(structstudent*)malloc(sizeof(structstudent));s->xh=xh;strcpy(s->xm,xm);s->bj=
8、bj;strcpy(s->sex,sex);strcpy(s->date,date);s->cj=cj;s->next=p->next;p->next=s;}voiddeletexs(){intxh;printf("请输入要删除的数据:");scanf("%d",&xh);p=head;while(p->next!=NULL){if(p->