您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > 学生信息管理系统C语言源代码
这个是用链表写的,功能应该比较全的,用链表可实现动态内存分配,方便存储人数不确定的信息#includestdio.h#includestdlib.h#includestring.h#includeconio.h#defineNULL0structstudent{charbianhao[10];charname[15];charxingbie[6];intnianling;intzongfen;charlicence[20];charaddress[40];charbeizhu[100];structstudent*next;};structstudent*creat()/////创建链表{structstudent*p,*head,*end;head=p=end=(structstudent*)malloc(sizeof(structstudent));//创建一个节点printf(====请输入学生信息====\n);printf(请输入学生编号:);scanf(%s,p-bianhao);while(strcmp(p-bianhao,0)!=0){end=p;printf(姓名:);scanf(%s,p-name);printf(性别:);scanf(%s,p-xingbie);printf(年龄:);scanf(%d,&p-nianling);printf(总分:);scanf(%d,&p-zongfen);printf(证件号:);scanf(%s,p-licence);printf(家庭住址:);scanf(%s,p-address);printf(备注:);scanf(%s,p-beizhu);p=(structstudent*)malloc(sizeof(structstudent));end-next=p;//end=p;printf(请输入学生编号:);scanf(%s,p-bianhao);}end-next=NULL;returnhead;}voidsave(structstudent*head)//保存链表为磁盘文件{FILE*fp;structstudent*p;charfilename[20];intch;printf(请输入要保存的文件名:);scanf(%s,filename);if((fp=fopen(filename,r))!=NULL){printf(该文件已经存在,是否覆盖?\n);printf(1、覆盖.2、不覆盖\n);scanf(%d,&ch);if(ch!=1){printf(请重新输入要保存的文件名:);scanf(%s,filename);}}if((fp=fopen(filename,w))==NULL){printf(创建文件失败!\n);return;//exit(0);正常退出,执行后显示pressanykeytocontinue;}//getchar();p=head;while(p!=NULL){fprintf(fp,%s\n,p-bianhao);fprintf(fp,%s\n,p-name);fprintf(fp,%s\n,p-xingbie);fprintf(fp,%d\n,p-nianling);fprintf(fp,%d\n,p-zongfen);fprintf(fp,%s\n,p-licence);fprintf(fp,%s\n,p-address);fprintf(fp,%s\n,p-beizhu);p=p-next;}fputs(over,fp);printf(文件保存成功!\n);//getchar();fclose(fp);}voidoutput(structstudent*head)//输出链表{structstudent*p;p=head;if(p==NULL){printf(未创建任何记录!\n);getchar();return;//head;}while(p!=NULL)//do{printf(编号:%s,p-bianhao);printf(\n姓名:%s,p-name);printf(\n性别:%s,p-xingbie);printf(\n年龄:%d,p-nianling);printf(\n总分:%d,p-zongfen);printf(\n证件号:%s,p-licence);printf(\n家庭地址:%s,p-address);printf(\n备注:%s\n,p-beizhu);p=p-next;}//while(p!=NULL);getchar();}structstudent*openfile()//打开文件,即新创建链表读取磁盘文件{structstudent*head,*p,*f;FILE*fp;charfilename[20];intch;printf(请输入要打开的文件名:);//若文件保存在默认路径,读取时无需输入路径scanf(%s,filename);if((fp=fopen(filename,r))==NULL){printf(打开文件失败!\n);printf(1、重新输入文件名2、退出\n);scanf(%d,ch);if(ch==1)scanf(%s,filename);elseif(ch==2)//getchar();//exit(0);returnNULL;}head=f=p=(structstudent*)malloc(sizeof(structstudent));fscanf(fp,%s%s%s%d%d%s%s%s,p-bianhao,p-name,p-xingbie,&p-nianling,&p-zongfen,p-licence,p-address,p-beizhu);while(!feof(fp)){p=(structstudent*)malloc(sizeof(structstudent));f-next=p;//节点连接fscanf(fp,%s%s%s%d%d%s%s%s,p-bianhao,p-name,p-xingbie,&p-nianling,&p-zongfen,p-licence,p-address,p-beizhu);if(strcmp(p-bianhao,over)==0){f-next=NULL;printf(文件打开成功,可显示信息!\n);getchar();returnhead;}f=p;}//fclose(fp);//f-next=NULL;//returnhead;}voidsort_hao(structstudent*head)//按编号排序{structstudent*p,*f,*t;charch[100];inti;p=f=t=head;if(head==NULL){printf(未打开任何文件!\n);getchar();return;}//ok//f=p-next;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(strcmp(t-bianhao,f-bianhao)0){strcpy(ch,t-bianhao);strcpy(t-bianhao,f-bianhao);strcpy(f-bianhao,ch);strcpy(ch,t-name);strcpy(t-name,f-name);strcpy(f-name,ch);strcpy(ch,t-xingbie);strcpy(t-xingbie,f-xingbie);strcpy(f-xingbie,ch);i=t-nianling;t-nianling=f-nianling;f-nianling=i;i=t-zongfen;t-zongfen=f-zongfen;f-zongfen=i;strcpy(ch,t-licence);strcpy(t-licence,f-licence);strcpy(f-licence,ch);strcpy(ch,t-address);strcpy(t-address,f-address);strcpy(f-address,ch);strcpy(ch,t-beizhu);strcpy(t-beizhu,f-beizhu);strcpy(f-beizhu,ch);}}}printf(完成排序!\n);getchar();//returnhead;}////循环判断,若此链表共有n个节点,则共需进行n^2次循环判断……………………voidsort_name(structstudent*head)//按学生姓名排序{structstudent*p,*f,*t;charch[100];inti;p=f=t=head;if(head==NULL){printf(文件未能打开!\n);getchar();return;//void类型无返回值,可以用return结束子程序以返回主程序,但return绝不能带回任何值}//f=p-next;for(p=head;p-next!=NULL;p=p-next){for(t=head,f=t-next;t-next!=NULL;t=t-next,f=f-next)//由于创建链表是以p-bianhao=0结束的故以f-next结束{if(strcmp(t-name,f-name)0){strcpy(ch,t-bianhao);strcpy(t-bianhao,f-bianhao);strcpy(f-bianhao,ch);strcpy(ch,t-name);strcpy(t-name,f-name);strcpy(f-name,ch);strcpy(ch,t-xingbie);strcpy(t-xingbie,f-xingbie);strcpy(f-xingbie,ch);i=t-nianling;t-nianling=f-nianling;f-nianling=i;i=t-zongfen;t-zongfen=f-zongfen;f-zongfen=i;strcpy(ch,t-licence);strcpy(t-licence,f-licence);strcpy(f-licence,ch);strcpy(ch,t-address);strcpy(t-address,f-address);strcpy(f-address,ch);strcpy(ch,t-beizhu);strcpy(t-beizhu,f-beizhu);strcpy(f-beizhu,ch);}}}printf(完成排序!\n);getchar();//returnhead;}voidsearch(structstudent*head)//查询{structstudent*p;charstr[20];inti,j=0;p=head;if(head==NULL){printf(未打开任何文件!);getchar();return;//}printf(1、按编号查询2、按姓名查询\n);scanf(%d,&i);if(i==1)printf(请输入编号:);elseprintf(请输入姓名:);scanf(%s,str);while(p!=NULL){if(i==1)//按编号查询,只输出一个结果,需保证编号不能重复{if(strcmp(p-bianhao,str)==0){printf(编号:%s\n姓名:%s\n性别:%s\n年龄:%d\n总分:%d\n证件号:%s\n家庭地址:%s\n备注:%s\n,p-bianh
本文标题:学生信息管理系统C语言源代码
链接地址:https://www.777doc.com/doc-6078945 .html