版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、学习 好资料#include <stdio.h>#include <stdlib.h>#include <conio.h> #include <dos.h> #include <string.h> #define LEN sizeof ( struct student)#define FORMAT"%-8d%-15s%-12.1lf%-12.1lf%-12.1lf%-12.1lfn"#define DATA stui.num,,stui.elec,stui.expe,stui.requ,stui.
2、sum float Ielec,Iexpe,Irequ;float Felec,Fexpe,Frequ;struct student /* 定义学生成绩结构体 */int num; /* 学号 */char name15; /* 姓名 */ double elec; /* 选修课 */ double expe; /* 实验课 */ double requ; /* 必修课 */ double sum; /* 总分 */;struct student stu50; /* 定义结构体数组 */ void input(); /* 录入学生成绩信息 */ void show(); /* 显示学生信息 *
3、/ void sort(); /* 按总分排序 */ void del(); /* 删除学生成绩信息 */ void modify(); /* 修改学生成绩信息 */ void menu(); /* 主菜单 */ void insert(); /* 插入学生信息 */ void total(); /* 计算总人数 */ void search(); /* 查找学生信息 */ main()int n; menu(); scanf( "%d",&n); while (n) switch (n)case 1: input();break ;case 2: search()
4、;break ;case 3: del();break ;case 4: modify();break ;case 5: insert();break ;case 6: sort();break ;case 7: total();break ;default : break ;menu(); scanf( "%d",&n); void show() FILE *fp;int i,m=0;fp=fopen( "d:data.txt", "ab+" );while (!feof(fp)if (fread(&stum ,LE
5、N,1,fp)=1) m+;fclose(fp);printf( "number name elective experiment required sumtn" for (i=0;i<m;i+)printf(FORMAT,DATA); /* 将信息按指定格式打印 */void menu()system( "cls" );printf( "n" );printf( "n" );printf( "t|Student management system|n");printf("t|n
6、"printf("t|0. exit|n"printf("t|n"printf("t|1. input record|n"printf("t|n"printf("t|2. search record|n"printf("t|n"printf("t|3. delete record|n"printf("t|n"printf("t|4. modify record|n"printf("t|n"
7、;printf("t|5. insert record|n"printf("t|n"printf("t|6. order|n"printf("t|n"printf("t|7. number|n"printf("t|n"printf("t|n"printf("n" );printf("n" );printf(I!choose( 0 7 ):");););););););););););););););););
8、););); void input() int i,m=0;char ch2;FILE *fp;if (fp=fopen( "d:data.txt" , "ab+" )=NULL) /* 打开指定文件 */printf( "can not openn" ); return ; /* 返回主函数 */while (!feof(fp) /*feof() 函数是用来判断指针是否已经到达文件尾部的, 若指针指向文件末尾,则返回值为 “真 ”, if (fread(&stum,LEN,1,fp)=1) m+; /* 统计当前记录条数 *
9、/ fclose(fp); if (m=0) printf( "No record!n" ); else system( "cls" );show(); /*调用show函数,显示原有信息*/if (fp=fopen( "d:data.txt" , "wb" )=NULL)printf( "can not openn" );return ; for (i=0;i<m;i+) fwrite(&stum,LEN,1,fp);/* 向指定磁盘文件写入信息 */printf( "
10、please input (y/n):/n");scanf( "%s",&ch);if (strcmp(ch, "y" )=0|strcmp(ch, "Y" )=0) printf("please input per centum:");printf("nelective:" );scanf( "%f" ,&Ielec);printf( "/nexperiment:" );scanf( "%f" ,&I
11、expe);printf( "/nrequired course:" );scanf( "%f" ,&Irequ);while (strcmp(ch, "y" )=0|strcmp(ch, "Y" )=0)printf( "number:" );scanf( "%d",&stum.num);/* 输入学生学号 */for (i=0;i<m;i+)if (stui.num=stum.num)返回。 */); printf( "the number
12、 is existing,press any to continue!"更多精品文档getch();fclose(fp);return ;printf( "name:" );scanf( "%s" ,&);/* 输入学生姓名 */printf( "elective:" );scanf( "%lf" ,&stum.elec); /* 输入选修课成绩 */ printf( "experiment:" );scanf( "%lf" ,&a
13、mp;stum.expe); /* 输入实验课成绩 */printf( "required course:");scanf( "%lf" ,&stum.requ); /* 输入必修课成绩 */ stum.sum=stum.elec*Ielec+stum.expe*Iexpe+stum.requ*Irequ;绩*/if (fwrite(&stum,LEN,1,fp)!=1) /* 将新录入的信息写入指定的磁盘文件/* 计算出总成*/printf( "can not save!" ); getch();elseprintf
14、( "%s saved!n" ,);m+;printf( "continue?(y/n):" scanf( "%s" ,ch);fclose(fp);printf( "OK!n" );); /* 询问是否继续 */void search()FILE *fp;int snum,i,m=0;char ch2;if (fp=fopen( "d:data.txt"printf( "can not openn"/* 自定义查找函数 */, "ab+"
15、; )=NULL);returnwhile (!feof(fp)if (fread(&stum,LEN,1,fp)=1)m+;if (m=0)printf( "no record!n");return ;printf( "please input the number:" );scanf( "%d",&snum); /* 输入需要查找学生的学号 */ for (i=0;i<m;i+)if (snum=stui.num) /* 查找出入的学号是否在记录中 */printf( "find the stude
16、nt,show?(y/n)");scanf( "%s" ,ch);if (strcmp(ch, "y" )=0|strcmp(ch, "Y" )=0)printf( "number name elective experiment requiredsumtn" );printf(FORMAT,DATA); /* 将查找出得结果按指定格式输出 */ break ;if (i=m)printf( "can not find the student!n"); /* 没有找到要查额信息 */s
17、ystem( "pause" );void modify() /* 自定义修改函数 */int i,j,snum,m=0;FILE *fp;if (fp=fopen( "d:data.txt" , "ab+" )=NULL)printf( "can not openn" );return ;while (!feof(fp)if (fread(&stum,LEN,1,fp)=1)m+;if (m=0)printf( "no record!n" ); fclose(fp);return ;p
18、rintf( "please input the number of the student which do you want to modify!n");scanf( "%d" ,&snum);for (i=0;i<m;i+)if (snum=stui.num) /* 检索记录中是否有要修改的信息 */ break ;if (i<m)printf( "find the student! you can modify now!n");printf( "please input per centnm:&q
19、uot;);printf( "nelective:" );scanf( "%f" ,&Ielec);printf( "nexperiment:" );scanf( "%f" ,&Iexpe);printf( "nrequired course:" ); scanf( "%f" ,&Irequ);printf( "name:n" );scanf("%s" ,&);printf( "
20、;nelective:" );scanf("%lf" ,&stui.elec);printf( "nexperiment:" );scanf("%lf" ,&stui.expe);printf( "nrequired course:" ); scanf("%lf" ,&stui.requ);stui.sum=stui.elec*Ielec+stui.expe*Iexpe+stui.requ*Irequ; else);, "wb" )=NULL
21、);printf( "can not find!" getch();return ;if (fp=fopen( "d:data.txt"printf( "can not openn" return ;for (j=0;j<m;j+)if (fwrite(&stuj,LEN,1,fp)!=1)printf( "can not save!" );getch();fclose(fp);void del() /* 自定义删除函数 */int snum,i,j,m=0;char ch2;FILE *fp;if
22、(fp=fopen( "d:data.txt" , "ab+" )=NULL) printf( "can not openn" ); return ;while (!feof(fp)if (fread(&stum,LEN,1,fp)=1)m+; fclose(fp);if (m=0) printf( "no record!n" );return ;);printf( "please input the number:"scanf( "%d" ,&snum);f
23、or (i=0;i<m;i+)if (snum=stui.num)break ;);printf( "find the student,delete?(y/n)"scanf( "%s" ,ch);ifif(strcmp(ch, "y" )=0|strcmp(ch, "Y" )=0) for (j=i;j<m;j+) stuj=stuj+1; m-;(fp=fopen( "d:data.txt","wb" )=NULL)文件中 */voidinsert() forp
24、rintf( "can not openn" return ;);(j=0;j<m;j+)if (fwrite(&stuj,LEN,1,fp)!=1)printf( "can not save!n" getch();fclose(fp);printf( "delete successfully!n"/* 自定义插入函数 */int i,j,k,snum,m=0; FILE *fp;(fp=fopen( "d:data.txt"ifprintf( "can not openn" re
25、turn ;););, "ab+" )=NULL); while (!feof(fp)if (fread(&stum,LEN,1,fp)=1) m+;if (m=0)printf( "no record!n" ); fclose(fp);return ;/* 将更改后的记录重新写入指定的磁盘printf( "please input the position where you want to insert!n");scanf( "%d",&snum); /* 输入要插入的位置 */for (i=0
26、;i<m;i+)if (snum=stui.num) break ;for (j=m-1;j>i;j-)stuj+1=stuj; /* 从最后一条记录开始均向后移一位 */ printf( "please input the new information:n");printf( "number:" );scanf( "%d" ,&stui+1.num);for (k=0;k<m;k+)if (stuk.num=stui+1.num&&k!=i+1)printf( "the numb
27、er is existing,press any to continue!");getch();fclose(fp);return ;printf( "please input per centum:");printf( "nelective:" );scanf( "%f" ,&Felec);printf( "nexperiment:" );scanf( "%f" ,&Fexpe);printf( "nrequired course:" );scan
28、f( "%f" ,&Frequ);printf( "name:n" );scanf("%s" ,&stui+1.name);printf( "nelective:" );scanf("%lf" ,&stui+1.elec);printf( "nexperiment:" );scanf("%lf" ,&stui+1.expe);printf("nrequired course:");scanf("%lf" ,&stui+1.requ);/*stui+1.sum=stui+1.elec*Felec+stui+1.expe*Fexpe+stui+1.requ*Frequ;计算总成绩 */if (fp=fopen( "d:data.txt", "wb" )=NULL)printf( "can not openn" ); return ;for (k=0;k<=m;k+)if (fwrite(&stuk,LEN,1,fp)!=1) /* 将修改后的
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 中铁轨道安全奖惩制度
- 车间生产管理流程制度
- 2025四川九洲投资控股集团有限公司软件与数据智能军团招聘行业经理等13人笔试历年难易错考点试卷带答案解析2套试卷
- 2025内蒙古鄂尔多斯电力冶金集团股份有限公司招聘23人笔试历年常考点试题专练附带答案详解
- 基于制度的京东物流行政管理工作探讨
- 家居建材业务员管理制度
- 业务员报销差旅制度
- 剧团业务部门制度
- p2p业务规章制度
- 商业银行中间业务制度
- 泵房调试要有方案
- 大众蔚揽保养手册
- 磁力泵讲义课件-参考
- 旅行社运营实务电子课件 2.1 走进旅行社门市
- 乳腺良性肿瘤日间手术临床路径临床路径
- 城镇供热管网工程施工及验收规范标准
- GB/T 26480-2011阀门的检验和试验
- GB/T 228.2-2015金属材料拉伸试验第2部分:高温试验方法
- C++初中组及答案
- 中考语文专题复习专题一汉字读写课件
- 麻醉复苏室课件
评论
0/150
提交评论