




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、运行结果:程序源码:#include#include#include#include#include#defineLENsizeof(structstudent)/求字节数运算符structstudentcharname20;longintnum;charsex4;intage;charaddress30;floatscore;structstudent*next;/链表;/定义一个结构题intTOTAL_NUM=0;/学生总数structstudent*head=NULL;voidmainmenu();/主界面voidrecord();/记录数据voidinsert(structstuden
2、t*stu);/插入数据voiddisplay(structstudent*stu);/显示一个学生的信息voiddisplayAll();/显示所有学生的信息voidquery();/查询学生信息voidquery_by_num();/按学号查询学生信息voidquery_by_name();voidreadData();/读取文件里学生的信息voidwriteData();/向文件写入学生信息voidfreeAll();/清空链表内容voiddel();/删除学生信息voidchange();/更改学生信息voidsort();/排序voiddevise(structstudent*p);
3、/选择更改内容intmain(void)mainmenu();return0;/系统主菜单voidmainmenu()intchoice;choice=-1;readData();printf(tttn);printf(ttt|欢迎使用通信工程专业学生信息管理系统|n);printf(tttn);printf(ttt本程序需要在当前目录下建立student.txt才可正常运行n);doprintf(nnn);printf(tttn);printf(ttt通信工程专业学生信息管理系统|n);printf(tttn);printf(ttt1录入学生信息|n);printf(ttt2浏览学生信息|n
4、);printf(ttt3查询学生信息|n);printf(ttt4删除学生信息|n);printf(ttt5修改学生信息|n);printf(ttt6排序|n);printf(ttt0退出系统|n);n);printf(tttprintf(请输入您的选择);scanf(%d,&choice);switch(choice)case0:writeData();freeAll();exit(0);case1:record();break;case2:displayAll();break;case3:query();break;case4:del();break;case5:change();bre
5、ak;case6:sort();break;default:printf(n无效选项!);break;while(choice!=0);/录入学生信息voidrecord()structstudent*p0;p0=(structstudent*)malloc(LEN);printf(ttt请输入学生的姓名:);scanf(%s,p0-name);printf(ttt请输入学生的学号:);scanf(%ld,&p0-num);printf(ttt请输入学生的性别:);scanf(%s,p0-sex);printf(ttt请输入学生的年龄:);scanf(%d,&p0-age);printf(tt
6、t请输入学生的地址:);scanf(%s,p0-address);printf(ttt请输入学生的成绩:);scanf(%f,&p0-score);insert(p0);printf(ttt该学生的信息为:n);printf(tttn);printf(ttt姓名t学号tt年龄t性别t地址tt成绩n);display(p0);voidinsert(structstudent*stu)structstudent*p0,*p1,*p2;p1=head;p0=stu;if (head = NULL)head=p0;p0-next=NULL;elsewhile(p0-nump1-num)&(p1-nex
7、t!=NULL)p2=p1;p1=p1-next;if(p0-numnum)if(head=p1)head=p0;elsep2-next=p0;p0-next=p1;elsep1-next=p0;p0-next=NULL;TOTAL_NUM+;voiddisplay(structstudent*p)printf(ttt%st%ldtt%dt%st%stt%fn,p-name,p-num,p-age,p-sex,p-address,p-score);/浏览学生信息voiddisplayAll()structstudent*p;printf(ttt学生总数:%dn,TOTAL_NUM);p=hea
8、d;if(head!=NULL)printf(ttt姓名t学号tt年龄t性别t地址tt成绩n);printf(tttn);dodisplay(p);p=p-next;while(p!=NULL);printf(n);voidquery()intchoice;choice=-1;doprintf(n);printf(n);printf(|按学号查询请按1|n);printf(|按姓名查询请按2|n);printf(|取消请按0|n);printf(+n);printf(请输入您的选择);scanf(%d,&choice);switch(choice)case0:return;case1:quer
9、y_by_num();break;case2:query_by_name();break;default:printf(n无效选项!);break;while(choice!=0);/按姓名查询学生信息voidquery_by_name()charname20;structstudent*p1;printf(请输入学生的姓名);scanf(%s,name);if(head=NULL)printf(无学生记录n);return;p1=head;while(strcmp(name,p1-name)&p1-next!=NULL)p1=p1-next;if(!strcmp(name,p1-name)p
10、rintf(ttt姓名t学号tt年龄t性别t地址tt成绩n);printf(tttAn);display(pl);elseprintf(没有该学生记录请核对”);/按学号查询学生信息voidquery_by_num()intnum;structstudent*p1;printf(请输入学生的学号);scanf(%ld,&num);if(head=NULL)printf(无学生记录n);return;p1=head;while(num!=p1-num&p1-next!=NULL)pl=p1-next;if(num=p1-num)printf(ttt姓名t学号tt年龄t性别t地址tt成绩n);pr
11、intf(tttAn);display(p1);elseprintf(ttt没有该学生记录请核对);/写入文件voidwriteData()FILE*fp;文件指针structstudent*p;fp=fopen(1.txt,w);if(!fp)printf(文件打开错误);return;fprintf(fp,%dn,TOTAL_NUM);for(p=head;p!=NULL;p=p-next)fprintf(fp,%st%ldt%st%dt%st%fn,p-name,p-num,p-sex,p-age,p-address,p-score);fclose(fp);voidfreeAll()st
12、ructstudent*p1,*p2;p1=p2=head;while(p1)p2=p1-next;free(p1);p1=p2;/读取文件voidreadData()FILE*fp;/文件指针structstudent*p1,*p2;fp=fopen(student.txt,r);if(!fp)printf(文件打开错误);return;fscanf(fp,%dn,&TOTAL_NUM);head=p1=p2=(structstudent*)malloc(LEN);fscanf(fp,%st%ldt%st%dt%st%fn,p1-name,&p1-num,p1-sex,&p1-age,p1-
13、address,&p1-score);while(!feof(fp)p1=(structstudent*)malloc(LEN);fscanf(fp,%st%ldt%st%dt%st%fn,p1-name,&p1-num,p1-sex,&p1-age,p1-address,&p1-score);p2-next=p1;p2=p1;p2-next=NULL;fclose(fp);/删除学生信息voiddel()structstudent*p1,*p2;longintnum;if(head=NULL)printf(无学生记录n);return;printf(请输入您要删除的学生的学号”);scanf
14、(%ld,&num);p1=head;while(num!=p1-num&p1-next!=NULL)p2=p1;p1=p1-next;if(num=p1-num)if(p1=head)head=p1-next;elsep2-next=p1-next;free(p1);TOTAL_NUM-;elseprintf(没有该学生记录请核对n);voidsort()/排序模块。将学生记录按学号从小到大排列。用起泡排序算法实现inti;structstudent*ptr,*s=head,*p;intcount=0,count1;while(s)/统计链表结点个数count+;s=s-next;for(i
15、=1;inext&(count1-)if(ptr-scoreptr-next-score)s=ptr-next;ptr-next=s-next;if(p=NULL)/ptr处于队头时head=s;elsep-next=s;s-next=ptr;p=s;elseptr=ptr-next;if(p=NULL)/ptr处于队头时p=head;elsep=p-next;displayAll();return;voidchange()structstudent*p1,*p2;longintnum;if(head=NULL)printf(无学生记录n);return;printf(请输入您要修改的学生的学
16、号);scanf(%ld,&num);p1=head;while(num!=p1-num&p1-next!=NULL)p2=p1;p1=p1-next;if(num=p1-num)devise(p1);elseprintf(没有该学生记录请核对n);voiddevise(structstudent*p)intchoice;choice=-1;doprintf(请选择您要修改的学生的信息内容n);printf(+n);printf(|姓名请按1|n);printf(|学号请按2|n);printf(|性别请按3|n);printf(|年龄请按4|n);printf(|地址请按5|n);printf(|爱好请按6|n);printf(|取消请按0|n);printf(+n);printf(请输入您的选择);scanf(%d,&choice);switch(choice)case0:return;case1:printf(请输入新姓名);scanf(%s,p-name);break;case2:prin
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年江西省南昌县莲塘第一中学高一物理第二学期期末考试模拟试题含解析
- 2025年陕西省延安市延川县中学物理高二第二学期期末统考模拟试题含解析
- 统编版2025届高二物理第二学期期末教学质量检测模拟试题含解析
- 2025年双鸭山市重点中学物理高一第二学期期末调研试题含解析
- 宠物日常护理课件大全
- 二零二五版高端商务空间设计施工协议书
- 2025版动画电影编剧聘用及创意开发合同
- 2025年度车床租赁与维护保养服务全面协议
- 二零二五年紧急救援搬运服务免责合同范本
- 二零二五年度重型货车挂靠运输合同协议书
- 百万销售日常管理办法
- 天津市南开区2024-2025学年七年级下学期期末考试数学试卷及答案
- 安全培训-重大事故隐患判定标准-专家版
- 2025年数据科学与大数据技术试题及答案
- 土木工程结构力学课件
- 2024年计算机二级WPS考试题库380题(含答案)
- 人教版小学英语单词表(完整版)
- 上海永大日立电梯按键的使用方法
- 注射用卡络磺钠销售培训学习资料
- WB/T 1069-2017乘用车运输服务通用规范
- MT 314-1992煤矿假顶用菱形金属网
评论
0/150
提交评论