




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
运行结果:程序源码:#include<stdio.h>#include<malloc.h>#include<string.h>#include<stdlib.h>求字节数运算符#include<conio.h>求字节数运算符#defineLENsizeof(structstudent)//structstudent{charname[20];longintnum;charsex[4];intage;charaddress[30];floatscore;structstudent*next;//链表};//定义一个结构题intTOTAL_NUM=0;//学生总数structstudent*head=NULL;voidmainmenu();//主界面voidrecord();//记录数据voidinsert(structstudent*stu);//插入数据voiddisplay(structstudent*stu);//显示一个学生的信息voiddisplayAll();//显示所有学生的信息voidquery();//查询学生信息voidquery_by_num();//按学号查询学生信息voidquery_by_name();voidreadData();//读取文件里学生的信息voidwriteData();//向文件写入学生信息voidfreeAll();//清空链表内容voiddel();//删除学生信息voidchange();//更改学生信息voidsort();//排序voiddevise(structstudent*p);//选择更改内容intmain(void){mainmenu();return0;}//系统主菜单voidmainmenu()intchoice;choice=-1;readData();printf("\t\t\t \n");printf("\t\t\t| 欢迎使用通信工程专业学生信息管理系统 |\n");printf("\t\t\t \n");printf("\t\t\t本程序需要在当前目录下建立student.txt才可正常运行\n");do{printf("\n\n\n");printf("\t\t\t \n");printf("\t\t\t通信工程专业学生信息管理系统|\n");printf("\t\t\t \n");printf("\t\t\t[1] 录入学生信息 |\n");printf("\t\t\t[2] 浏览学生信息 |\n");printf("\t\t\t[3] 查询学生信息 |\n");printf("\t\t\t[4] 删除学生信息 |\n");printf("\t\t\t[5] 修改学生信息 |\n");printf("\t\t\t[6] 排序|\n");printf("\t\t\t[0] 退出系统|\n");\n");printf("\t\t\t\n");printf("请输入您的选择");scanf("%d",&choice);switch(choice){case0:writeData();freeAll();exit(0);case1:record();break;case2:displayAll();break;case3:query();break;case4:del();break;case5:change();break;case6:sort();break;default:printf("\n无效选项!");break;}}while(choice!=0);}//录入学生信息voidrecord(){structstudent*p0;p0=(structstudent*)malloc(LEN);printf("\t\t\t请输入学生的姓名:");scanf("%s",p0->name);printf("\t\t\t请输入学生的学号:");scanf("%ld",&p0->num);printf("\t\t\t请输入学生的性别:");scanf("%s",p0->sex);printf("\t\t\t请输入学生的年龄:");scanf("%d",&p0->age);printf("\t\t\t请输入学生的地址:");scanf("%s",p0->address);printf("\t\t\t请输入学生的成绩:");scanf("%f",&p0->score);insert(p0);printf("\t\t\t该学生的信息为:\n");printf("\t\t\t \n");printf("\t\t\t姓名\t学号\t\t年龄\t性别\t地址\t\t成绩\n");display(p0);}voidinsert(structstudent*stu){structstudent*p0,*p1,*p2;p1=head;p0=stu;if(head==NULL)head=p0;p0->next=NULL;}else{while((p0->num>p1->num)&&(p1->next!=NULL)){p2=p1;p1=p1->next;}if(p0->num<=p1->num){if(head==p1)head=p0;elsep2->next=p0;p0->next=p1;}else{p1->next=p0;p0->next=NULL;TOTAL_NUM++;}voiddisplay(structstudent*p){printf("\t\t\t%s\t%ld\t\t%d\t%s\t%s\t\t%f\n",p->name,p->num,p->age,p->sex,p->address,p->score);}//浏览学生信息voiddisplayAll(){structstudent*p;printf("\t\t\t学生总数:%d\n",TOTAL_NUM);p=head;if(head!=NULL){printf("\t\t\t姓名\t学号\t\t年龄\t性别\t地址\t\t成绩\n");printf("\t\t\t \n");do{display(p);p=p->next;while(p!=NULL);}printf("\n");}voidquery(){intchoice;choice=-1;do{printf("\n");printf(" \n");printf("|按学号查询请按1|\n");printf("|按姓名查询请按2|\n");printf("|取消请按0|\n");printf("+ +\n");printf("请输入您的选择");scanf("%d",&choice);switch(choice){case0:return;case1:query_by_num();break;case2:query_by_name();break;default:printf("\n 无效选项!”);break;}}while(choice!=0);}//按姓名查询学生信息voidquery_by_name(){charname[20];structstudent*p1;printf("请输入学生的姓名");scanf("%s",name);if(head==NULL){printf("无学生记录 \n”);return;}p仁head;while(strcmp(name,p1->name)&&p1->next!=NULL)p1=p1->next;if(!strcmp(name,p1->name)){printf("\t\t\t姓名\t学号\t\t年龄\t性别\t地址\t\t成绩\n");printf("\t\t\t \n");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("\t\t\t姓名\t学号\t\t年龄\t性别\t地址\t\t成绩\n");printf("\t\t\t \n");display(p1);}elseprintf("\t\t\t没有该学生记录请核对 ”);}//写入文件voidwriteData(){FILE*fp;〃文件指针structstudent*p;fp=fopen("1.txt","w");if(!fp){printf("文件打开错误 Lreturn;}fprintf(fp,"%d\n",TOTAL_NUM);for(p=head;p!=NULL;p=p->next){fprintf(fp,"%s\t%ld\t%s\t%d\t%s\t%f\n",p->name,p->num,p->sex,p->age,p->address,p->score);}fclose(fp);}voidfreeAll(){structstudent*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,"%d\n",&TOTAL_NUM);head=p1=p2=(structstudent*)malloc(LEN);fscanf(fp,"%s\t%ld\t%s\t%d\t%s\t%f\n",p1->name,&p1->num,p1->sex,&p1->age,p1->address,&p1->score);while(!feof(fp)){p1=(structstudent*)malloc(LEN);fscanf(fp,"%s\t%ld\t%s\t%d\t%s\t%f\n",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("%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=1;i<count;i++){ptr=head;p=NULL;个结点while(ptr&&ptr->next&&(count1--)){if(ptr->score>ptr->next->score){s=ptr->next;ptr->next=s->next;if(p==NULL)〃ptr处于队头时head=s;elsep_>next=s;s->next=ptr;p=s;}else{ptr=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("请输入您要修改的学生的学号");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(structstuden
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 中介卖房合同协议书范本
- 2025年农村电商服务站农村电商市场拓展策略:运营模式创新与风险控制报告
- 动植物管理员面试题及答案
- 文化遗产数字化展示与传播策略在数字文化遗产保护项目成本控制中的应用报告
- 2025年基层医疗机构信息化建设与家庭医生签约服务报告
- 二手奢侈品市场2025年交易规范与行业规范执行现状调查与分析及优化策略及实施
- 2025年教育平台用户增长策略优化:内容创新与课程设计报告
- 2025年餐饮行业老字号品牌餐饮市场拓展与创新研究报告
- 工业互联网平台安全多方计算在智慧农业设备故障诊断与分析中的应用前景报告
- 2025年智能家居系统互联互通标准下的智能家居行业市场潜力及增长预测报告
- FZ/T 93029-2016塑料粗纱筒管
- 2022年12月山东省普通高中学业水平合格性考试语文仿真模拟试卷C(答题卡)
- 塑胶原料来料检验指导书
- 人教版音乐三年级下册知识总结
- 共点力平衡的应用-完整版PPT
- 建筑物的防雷及安全用电电子教案
- 中国近现代史社会实践报告-2000字
- 系杆拱桥工程测量施工方案
- ISA-300+使用-300技术使用说明书
- 高层建筑“一栋一册”消防安全档案
- 柳洲学校学生仪容仪表日常检查记录表
评论
0/150
提交评论