




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、#include<stdio.h>#include<stdlib.h>#include<string.h>#include<ctype.h>#include<conio.h>struct student char number21;char name21; int age;char sex3; char birthday8;studentArray100;typedef struct student student;student studentArray100;char putout512="学号","
2、姓名","年龄","性别","出生年月" /为格式化输出做准备int count=0;/函数声明部分void explain();void readfile();void searchStudent();void modifyStudent();void addStudent();void delStudent();void printAllstudent();void save();void quit();void initial();void initial()FILE *fp;char choice='y
3、9;int i=0;fp=fopen("e:students.txt","r");if(!fp)printf("创建文件失败,即将返回n");return ;for(;fread(&studentArrayi,sizeof(struct student),1,fp)!=0;i+);count=i;/0、说明模块void explain()printf("n 很高兴能为您服务n");printf("n1.进入本系统,请先刷新学生信息,再查训n");printf("n2.您可以根据
4、自己需要的信息键入菜单上的编号n");printf("n3.修改学生信息后记得退出前保存信息,以免信息流失n");printf("n4.在各个子菜单里按提示操作n");printf("n5.谢谢您的使用及支持n");/1、刷新模块void readfile() char *p="students.txt" FILE *fp; int i=0; if(fp=fopen("students.txt","r")=NULL) printf("打开文件%s出错!请按
5、按任意键返回",p); system("pause"); return ; while(fscanf(fp,"%s %s %d %s %s",&studentArrayi.number,&studentA,&studentArrayi.age,&studentArrayi.sex,&studentArrayi.birthday)=5) i+; i=i; fclose(fp); printf("刷新完毕。n"); /2、查询模块void searchStudent()
6、 int i;int jb; FILE *fp;char studentNumber21;char studentName21;int flag=0;fp=fopen("e:students.txt","rb");if(count=0)printf("文件中还没有学生记录,请继续其他操作nn");return ;printf("1.按学号查询n"); printf("2.按姓名查询n");printf("3.不查询,退出n");while(1) printf("请选
7、择子菜单编号:"); scanf("%d",&jb); flag=0; switch(jb) case 1: printf("请输入要查询的学生的学号:n"); scanf("%s",&studentNumber); for(i=0;i<=count;i+)if(strcmp(studentNumber,studentArrayi.number)=0) flag=1;printf("要查找的学生相关信息如下:n");printf("学号 姓名 年龄 性别 出生年月n&quo
8、t;);printf("%s %8s %7d %4s %8sn",studentArrayi.number,studentA,studentArrayi.age,studentArrayi.sex,studentArrayi.birthday);printf("n");printf("n");if(flag=0)printf("没有找到学号为%s的学生n", studentNumber);printf("n");return ;return ;case 2: printf(&
9、quot;请输入要查询的学生的姓名:n"); fflush(stdin);scanf("%s",&studentName);for(i=0;i<=count;i+) if(strcmp(studentA,studentName)=0) flag=1;printf("要查找的学生相关信息如下:n");printf("学号 姓名 年龄 性别 出生年月n");printf("%s %8s %7d %4s %8sn",studentArrayi.number,studentArr
10、,studentArrayi.age,studentArrayi.sex,studentArrayi.birthday);printf("n");printf("n");if(flag=0)printf("没有找到名字为%s的学生n", studentName);printf("n");return ;case 3:return;/3、修改模块void modifyStudent()FILE *fp,*fp2;int flag=0;int i;int a,n;char studentNumber21
11、;/char c;student newdata;fp=fopen("e:students.txt","rb");if(count=0)printf("文件中还没有学生信息,即将退出nn");return ;fp2=fopen("e:test.txt","wb");if(!fp2)printf("文件创建失败,即将返回n"); return ;printf("输入要修改的学生的学号n");fflush(stdin);scanf("%s"
12、,&studentNumber);for(n=0;n<=count;n+)if(strcmp(studentArrayn.number,studentNumber)=0)a=n;for(i=0;fread(&studentArrayi,sizeof(struct student),1,fp)!=0;i+)if(!strcmp(studentArrayi.number,studentNumber)flag=1;printf("将要要修改的学生信息:n");printf("%s %8s %7d %4s %8sn",studentArra
13、ya.number,studentA,studentArraya.age,studentArraya.sex,studentArraya.birthday);printf("输入要修改后学生的学号、姓名、年龄、性别、出生年月,中间以空格隔开,回车键结束n");printf(" (学号格式:001) (出生年月格式:1995-03) n");fflush(stdin);scanf("%s%s%d%s%s",&newdata.number,&,&newdata.age,&
14、amp;newdata.sex,&newdata.birthday);fwrite(&newdata,sizeof(struct student),1,fp2);elsefwrite(&studentArrayi,sizeof(struct student),1,fp2);if(flag=0)printf("没有此人,即将退出nn");return ;fclose(fp);fclose(fp2);fp=fopen("e:students.txt","wb");fp2=fopen("e:test.txt
15、","rb");for(i=0;fread(&studentArrayi,sizeof(struct student),1,fp2)!=0;i+)fwrite(&studentArrayi,sizeof(struct student),1,fp); printf("nn");fclose(fp);fclose(fp2);printf("已成功修改该学生信息。n");/4、添加模块void addStudent() FILE *fp;char choice='y'int i=0;fp=fopen
16、("e:students.txt","ab");if(!fp)printf("创建文件失败,即将返回nn");return ;while(choice='y')printf("输入学生学号、 姓名、年龄、性别、出生年月,中间以空格隔开,以回车键结束n");printf(" (学号格式:001) (出生年月格式:1995-03) n");fflush(stdin);scanf("%s%s%d%s%s",&studentArrayi.number,&
17、;studentA,&studentArrayi.age,&studentArrayi.sex,&studentArrayi.birthday);fwrite(&studentArrayi,sizeof(struct student),1,fp); /将数据写入文件中i+;count+;printf("是否继续输入,继续输入输入y,其它值退出n");fflush(stdin);choice=getchar();choice=tolower(choice);fflush(stdin); /清空缓存输入流fclose(fp);
18、printf("输入任意键继续nn");getch();return ;/5、删除模块void delStudent() FILE *fp ,*fp2;int i;char choice;int flag1=1;int flag2=0; int found=0; /用来标记文件中是否含有此人 char studentNumber21;char studentName21;fp=fopen("e:students.txt","rb");if(count=0)printf("文件中没有信息,即将退出nn");/getc
19、h();return ;fp2=fopen("e:test.txt","wb");if(!fp2)printf("文件创建失败,即将退出n");return;printf("n");printf("1. 按照学号删除学生信息n");printf("2. 按照名字删除学生信息n");printf("3. 删除所有学生信息n");printf("n");printf(" 请选择菜单编号:");i=0;found=0;sc
20、anf("%d",&flag2);fflush(stdin);if(flag2=1)printf("输入要删除的学生的学号,按回车键结束n");scanf("%s",studentNumber);for(i=0;fread(&studentArrayi,sizeof(struct student),1,fp)!=0;i+) /将其他人信息转移到test.txt文件中if(strcmp(studentArrayi.number,studentNumber)fwrite(&studentArrayi,sizeof(
21、struct student),1,fp2);elsefound=1;fclose(fp);fclose(fp2);fflush(stdin);if(found=1)printf("是否确认删除学号为%s该学生信息,确认删除,输入y:n",studentNumber);elseprintf("没有此人信息,即将退出n");return ;choice=getchar();if(choice='y') /将文件结构指针重新定向count-;fp=fopen("e:students.txt","wb")
22、;fp2=fopen("e:test.txt","rb");for(i=0;fread(&studentArrayi,sizeof(struct student),1,fp2)!=0;i+)fwrite(&studentArrayi,sizeof(struct student),1,fp);fclose(fp);fclose(fp2);else if(flag2=0)printf("输入要删除的学生的名字,按回车键结束n");scanf("%s",studentName);for(i=0;fread
23、(&studentArrayi,sizeof(struct student),1,fp)!=0;i+) /将其他人信息转移到test.txt文件中if(strcmp(studentA,studentName)fwrite(&studentArrayi,sizeof(struct student),1,fp2);else found=1;fclose(fp);fclose(fp2);fflush(stdin);if(found=1)printf("是否确认删除名字为%s的该学生信息,确认删除,输入y:",studentName);elsep
24、rintf("没有此人信息,即将退出nn");return;choice=getchar();if(choice='y') /将文件结构指针重新定向count-;fp=fopen("e:students.txt","wb");fp2=fopen("e:test.txt","rb");for(i=0;fread(&studentArrayi,sizeof(struct student),1,fp2)!=0;i+)fwrite(&studentArrayi,sizeo
25、f(struct student),1,fp);fclose(fp);fclose(fp2); else if(flag2=3)char ch;printf("你确认删除所有学生记录吗?继续输入y,停止输入其他n");fflush(stdin);ch=getchar();if(ch='y')fp=fopen("e:students.txt","wb");count=0;printf("已删除所有学生记录n");return ;elseprintf("输入错误n");/6、显示模块
26、void printAllstudent() FILE *fp;int i; fp=fopen("e:students.txt","rb");if(count=0)printf("文件中还没有学生信息,即将退出nn");return;printf("有%d各学生的信息如下:n",count); printf("学生学号 学生姓名 年龄 性别 出生年月 n"); for(i=0;fread(&studentArrayi,sizeof(struct student),1,fp)!=0;i+)
27、 printf("%6s %9s %7d %5s %9sn",studentArrayi.number,studentA,studentArrayi.age,studentArrayi.sex,studentArrayi.birthday); return;/7、保存模块void save() int i; FILE *fp; fp=fopen("students.txt","w"); for(i=0;i<count;i+) fprintf(fp,"%s %s %d %s %s n",st
28、udentArrayi.number,studentA,studentArrayi.age,studentArrayi.sex,studentArrayi.birthday); fclose(fp); /8、退出模块void quit() printf("*n");printf("* *n");printf("* 谢谢使用! *n");printf("* 再见! *n");printf("* *n");printf("*n");/菜单模块int menuselect()int choice;doprintf(" 欢迎进入学生信息管理系统 n");printf(" n");printf(" *系统功能菜单*n");printf(" + +n");printf(" * 友情提示:查询前请先刷新系统 *n");printf(" + - - +n");printf(" * * *n");printf(&quo
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- DB32/T 4006.1-2021医务人员个体防护装备选用规范第1部分:生物危害防护
- DB32/T 3873-2020增材制造用塑料线材热熔产生烷烃类物质和醛酮类物质的测定
- DB32/T 3764-2020医疗污水病毒检测样品制备通用技术规范
- DB32/T 3597-2019增材制造金属材料机械性能测试方法指南
- DB31/T 534-2011通信网络运营环节的节能要求
- DB31/T 1282-2021车用气瓶氢气充装安全技术条件
- 个人股权收购与投资管理一体化合同
- DB31/T 1184-2019特种设备隐患分类分级导则
- 农业项目股权转让及土地流转合同规范
- 智能家居股东股份制合同协议书
- 店面出让股权协议书
- 深圳2025年深圳市住房公积金管理中心员额人员招聘8人笔试历年参考题库附带答案详解
- 英文电影鉴赏知到智慧树期末考试答案题库2025年北华大学
- 美容诊所合作协议书
- 2025年人教版小学一年级下学期奥林匹克数学竞赛试卷(附答案解析)
- 2025年滁州市轨道交通运营有限公司第二批次招聘31人笔试参考题库附带答案详解
- 2025年高考英语考前热点话题押题卷(新高考Ⅰ卷)-2025年高考英语模拟考试(解析版)
- 浙江国企笔试题目及答案
- 电力现场安全管理课件
- 分子生物学技术在检验中的应用试题及答案
- 中考语文专题一非连续性文本阅读市公开课一等奖市赛课获奖课件
评论
0/150
提交评论