学生信息管理系统(C语言基于链表文件).doc
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 学生 信息管理 系统 语言 基于 文件
- 资源描述:
-
#include〈stdio.h> #include<stdlib。h〉 #include〈conio。h〉 #include〈windows。h〉 #include〈string。h> #define LEN sizeof(struct student) #define DAT_FILENAME ”Information。txt” /**********************定义数据结构********************/ struct date { int year; int month; int day; }; struct student { int ID; char Name[8]; int age; char xb; char telephone[15]; char address[40]; struct date birthday; char email[40]; struct student *next; }; /*************************函数原型*********************/ void DispMainMenu(); void DisplayInformation(struct student *head); struct student *FindstudentID(struct student *head,int findID); struct student *FindstudentName(struct student *head,char findname[]); struct student *InformationInput(struct student *head); void QueryInformation(struct student *head); struct student *EditInformation(struct student *head); struct student *Insert(struct student *head,struct student *p); void Save(struct student *head); struct student *Read(struct student *head); struct student *Delete(struct student *head,int findID); struct student *Add(struct student *head); void Help(); /************************显示主菜单***************************/ void DispMainMenu() { printf("*********************************学生信息管理系统******************************\n”); printf(”\n”); printf(”\t\t\t\t1-—信息录入\n"); printf("\n"); printf("\t\t\t\t2-—信息修改\n"); printf(”\n”); printf("\t\t\t\t3-—信息查询\n”); printf(”\n”); printf(”\t\t\t\t4—-保存数据到文件\n"); printf(”\n”); printf(”\t\t\t\t5-—打开数据文件\n”); printf("\n”); printf("\t\t\t\t6—-文件追加\n”); printf("\n"); printf(”\t\t\t\t7-—帮助\n”); printf(”\n”); printf(”\t\t\t\t0--退出\n”); printf(”\n"); printf(”友情提示:初次使用请先阅读帮助\n"); printf("*******************************************************************************\n”); printf("请选择(0—7):”);/*显示主菜单*/ } /*************************************帮助**************************************************/ void Help() { printf("\n\t\t\t欢迎进入帮助系统!\n\n”); printf("\t1。请按照主菜单提示选择所需执行功能的数字代号!\n”); printf("\t2.所有文件请按照规范输入\n"); printf("\t3.刚开始执行程序时若需要文本文件里的数据,请先进行读取文件信息!\n"); printf(”\t4。修改信息以后,请切记需要保存!\n”); printf(”\n"); } /***********************显示所有学生信息**********************/ void DisplayInformation(struct student *head) { struct student *p; printf(”*******************************************************************************”); printf(”\n学号\t姓名\t年龄\t性别\t 电话\t\t地址\t 出生年月\t email\n"); p=(struct student *)malloc(LEN); p=head; if(head!=NULL) while(p!=NULL) { printf("%—d\t%—s\t%-d\t”,p—〉ID,p—〉Name,p->age); printf(”%—c\t%—s\t%—s\t",p—〉xb,p—〉telephone,p-〉address); printf(”%—d %d %d”,p—〉birthday。year,p-〉birthday。month,p->birthday.day); printf(”\t%-s\n",p—>email); p=p—〉next; } else printf(”无数据\n"); } /**************************查找指定学号的学生信息******************************/ struct student *FindstudentID(struct student *head,int findID) { struct student *p; p=(struct student *)malloc(LEN); p=head; if(head!=NULL) while(p!=NULL) { if(p-〉ID==findID) break; p=p->next; } else printf("无数据\n”); return p; } /***************************查找指定姓名的学生信息**********************/ struct student *FindstudentName(struct student *head,char findname[]) { struct student *p; p=(struct student *)malloc(LEN); p=head; if(head!=NULL) while(p!=NULL) { if(strcmp(p—〉Name,findname)==0) break; p=p->next; } else printf(”无数据\n"); return p; } /********************学生信息录入**********************************/ struct student *InformationInput(struct student *head) { int number,i; struct student *p; p=(struct student *)malloc(LEN); printf(”\n请输入本次录入的学生人数:"); scanf("%d”,&number); for(i=0;i〈number;i++)/*输入 number 个学生的信息*/ { printf("请输入第%d个学生的学号(八个字符以内):”,i+1); scanf("%d”,&p-〉ID); printf("\t\t\t 姓名:\t”); scanf("%s”,p—>Name); printf(”\t\t\t 年龄:\t"); scanf(”%d”,&p—〉age); printf(”\t\t\t 性别(男M、女W):”); scanf("%s",&p—〉xb); printf(”\t\t\t 电话(八位):\t"); scanf(”%s”,p—>telephone); printf("\t\t\t 地址:\t”); scanf("%s”,p-〉address); printf("\t\t\t 出生年月:\t”); scanf("%d%d%d",&p—〉birthday.year,&p—〉birthday。month,&p->birthday。day); printf("\t\t\temail:\t"); scanf("%s",p—>email); head=Insert(head,p); p=(struct student *)malloc(LEN); } printf("\n 您的输入信息是:\n”); DisplayInformation(head); return(head); } /**************************学生信息查询*************************/ void QueryInformation(struct student *head) { char select; int findID; char findname[8]; struct student *p; printf("*********************请选择查询方式*************************\n”); printf("\t1-—按学号查询;\t2——按姓名查询\n”); printf(”************************************************************\n”); printf(”请选择(1-2):");/*显示菜单信息*/ select=getche(); getch(); switch (select) { case’1’: printf("\n 按学号查询\n 请输入学生的学号:”); scanf(”%d",&findID); if((p=FindstudentID(head,findID))!=NULL) /*找到指定学号的学生*/ { printf(”\n 查找结果如下:\n”); printf(”\n学号\t姓名\t年龄\t性别\t 电话\t\t地址\t 出生年月\t email\n"); printf(”%d\t%s\t%d\t”,p—>ID,p-〉Name,p—>age); printf(”%c\t%s\t%s\t”,p—〉xb,p-〉telephone,p—〉address); printf("%d %d %d",p—>birthday。year,p—〉birthday。month,p—>birthday。day); printf(”\t%s\n”,p—〉email); } else /*没有找到*/ printf(”您输入的学号不存在!\n”); break; case’2’: printf(”\n 按姓名查询\n 请输入学生的姓名:”); scanf("%s",&findname); if((p=FindstudentName(head,findname))!=NULL) /*找到指定姓名的学生*/ { printf("\n 查找结果如下:\n"); printf(”\n 学号\t 姓名\t 年龄\t 性别\t 电话\t 地址\t 出生年月\t email\n”); printf("%d\t%s\t%d\t",p—〉ID,p-〉Name,p->age); printf(”%c\t%s\t%s\t”,p—>xb,p—〉telephone,p—〉address); printf(”%d %d %d”,p-〉birthday。year,p—〉birthday。month,p—〉birthday.day); printf(”\t%s\n”,p->email); } else /*没有找到*/ printf(”您输入的姓名不存在!\n”); break; default: printf(”选择错误!\n"); } } /*********************************修改学生信息***********************/ struct student *EditInformation(struct student *head) { int findID; char select; struct student *p; printf("\n 请输入学生的学号:"); scanf(”%d”,&findID); if((p=FindstudentID(head,findID))!=NULL) /*找到指定学号的学生*/ { printf(”*********************请修改方式*************************\n”); printf(”\t1——修改信息;\t2——删除信息\n"); printf(”************************************************************\n"); printf("请选择(1—2):"); select=getche(); getch(); switch (select) { case’1’: /*修改信息*/ printf(”您选择的是修改信息!\n”); printf(”姓 名:%s\n”,p—>Name); printf(”原信息:学号:%d\t 年龄:%d\t 性别:%c\n”,p->ID,p—>age,p-〉xb); printf("\t 电话:%s\t 地址:%s\temail:%s\n",p-〉telephone,p—>address,p—〉email); printf(”请输入新信息\n"); printf(”学号\t”); scanf("%d”,&p—〉ID); printf("姓名:\t”); scanf(”%s”,p—〉Name); printf(”年龄:\t”); scanf(”%d",&p->age); printf("性别(男M、女W):”); scanf(”%s”,&p—〉xb); printf(”电话:\t”); scanf(”%s”,p->telephone); printf(”地址:\t”); scanf(”%s”,p—〉address); printf(”出生年月:\t”); scanf(”%d%d%d”,&p-〉birthday。year,&p->birthday。month,&p—〉birthday。day); printf(”email:\t”); scanf("%s",p—>email); break; case’2’: /*删除信息*/ printf(”您选择的是删除信息!\n"); head=Delete(head,findID); break; } } else /*没有找到学号匹配的记录*/ printf(”您输入的学号不存在!\n"); return (head); } /**************************有序插入***************************************/ struct student *Insert(struct student *head,struct student *p) { struct student *p0,*p1; if(head==NULL) { head=p; p->next=NULL; return(head); } if(p-〉ID〈head—〉ID) { p->next=head; head=p; return(head); } p1=head; while((p—〉ID>p1—>ID)&&(p1—〉next!=NULL)) { p0=p1; p1=p1—〉next; } if(p-〉ID〈p1—〉ID) { p—>next=p1; p0-〉next=p; } else { if(p->ID==p1—>ID) ; else { p1—〉next=p; p—〉next=NULL; } } return(head); } /*******************************保存数据到文件**************************/ void Save(struct student *head) { FILE *fp; struct student *p; p=head; if((fp=fopen(DAT_FILENAME,”w+”))!=NULL) /*以W+的方式打开文件*/ { while(p!=NULL) { fprintf(fp,”%d\t”,p-〉ID); fprintf(fp,”%s\t",p—〉Name); fprintf(fp,”%d\t",p—〉age); fprintf(fp,"%c\t",p->xb); fprintf(fp,"%s\t",p—〉telephone); fprintf(fp,”%s\t”,p—〉address); fprintf(fp,"%d %d %d\t",p—〉birthday.year,p—〉birthday.month,p—〉birthday.day); fprintf(fp,”%s\n”,p—〉email); p=p—>next; } /*将链表的内容写入文件*/ fclose(fp); } else printf(”cannot open file\n”); } /***************************打开数据文件************************/ struct student *Read(struct student *head) { struct student *p; p=(struct student *)malloc(LEN); FILE *fp; if((fp=fopen(DAT_FILENAME,”r"))!=NULL) { /*读取文件中的内容到链表中*/ while(fscanf(fp,”%d\t",&p-〉ID)!=EOF) { fscanf(fp,"%s\t",p->Name); fscanf(fp,"%d\t”,&p—>age); fscanf(fp,"%c\t”,&p->xb); fscanf(fp,”%s\t",p—>telephone); fscanf(fp,”%s\t”,p->address); fscanf(fp,”%d %d %d\t",&p-〉birthday。year,&p—〉birthday。month,&p—〉birthday.day); fscanf(fp,"%s\n”,p—>email); head=Insert(head,p); p=(struct student *)malloc(LEN); } fclose(fp); } else printf(”cannot open file\n"); return head; } /**************************文件内容追加************************/ struct student *Add(struct student *head) { head=Read(head); head=InformationInput(head); return (head); } /**************************删除信息****************************/ struct student *Delete(struct student *head,int findID) { struct student *pre,*p; if(head—>ID==findID) { p=head; head=head—〉next; } else { pre=head; p=pre—〉next; while(p!=NULL&&p-〉ID!=findID) { pre=p; p=p—〉next; } if(p—〉ID==findID) pre—〉next=p—〉next; } free(p); return (head); } /*********************************主函数***************************/ void main() { char select,c; struct student *head; head=NULL; select=0; while(select!=’0') { DispMainMenu(); select=getche(); getch(); switch(select) { case'0’: printf(”\n您选择的是退出!\n"); _beep(300,400); continue; case’1': system(”cls”); printf("\n您选择的是信息录入!\n”); head=InformationInput(head); break; case’2’: system("cls”); printf("\n您选择的是信息修改!\n”); head=EditInformation(head); break; case’3’: system("cls"); printf("\n您选择的是信息查询!\n”); QueryInformation(head); break; case’4’: system("cls”); printf(”\n您选择的是保存数据到文件!\n"); Save(head); break; case'5': system("cls”); printf(”\n您选择的是打开数据文件!\n”); if((head=Read(head))!=NULL) DisplayInformation(head); break; case'6’: system(”cls"); printf(”\n您选择的是文件追加!\n”); head=Add(head); break; case'7’: system("cls”); printf(”\n您选择的是帮助!\n”); Help(); break; default: printf(”\n选择错误!请重新选择!\n”); } printf(”请选择返回主界面或退出!\n"); //选择是否继续 printf("主界面:1\t退出:2\t”); scanf(”%d",&c); while(!(c==1||c==2)) { printf(”选择错误,请重新选择!”); printf("\n主界面:1\t退出:2\t”); scanf(”%d",&c); } if(c==1) system("cls”); else { system("cls"); _beep(300,400); printf(”\n\t您已安全退出!\n”); break; } } }展开阅读全文
咨信网温馨提示:1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。




学生信息管理系统(C语言基于链表文件).doc



实名认证













自信AI助手
















微信客服
客服QQ
发送邮件
意见反馈



链接地址:https://www.zixin.com.cn/doc/3941274.html