




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、- 29 -c语言课程设计报告 题目:教务管理程序该程序是一个简单的教务管理程序. 它可以录入多个班级的同学的基本情况:学号、姓名、性别、年龄、宿舍号码、电话号码, 同时还可以输入每个同学的各门功课的成绩, 并且能够将所有学生的基本情况和各课的成绩作适当修改和删除以及统计,同时能够将各班的总的成绩情况输出.一:数据结构设计及用法说明在整个程序中采用了多种数据结构,包刮有基本类型中的:1:整型int 、char、long。2:浮点型:double、float。3:导出类型:指针、数组、结构(struct)。程序中的几个主要的结构:/*定义数据结构类型*/typedef struct long n
2、um; /*学号*/ char name 15; /*姓名*/ char sex; /*性别*/ int age; /*年龄*/ int m; /*学生在班级中的位置标志*/ int n; /*班级号*/ long room_num; /*宿舍号码*/ long tele_num; /*电话号码*/ sco score10; /*成绩结构数组*/ float k; /*平均成绩*/stud;/*支链结点*/struct branchnode stud student; struct branchnode * next;/*主链结点*/struct mainnode int data; stru
3、ct mainnode * trunk; struct branchnode * branch; 程序中建立了多个函数分别来完成每个所要求的功能:读文件和写文件函数,建链表函数,插入、修改和删除函数,排序、统计和输出函数.程序利用各个函数来完成前面要求所需要的功能。 二:程序结构head学生n的基本情况和各门功课成绩学生2的基本情况和各门功课的成绩学生1的基本情况和各门功课的成绩班级1struct *next 班级2struct *next-学生n的基本情况和各门功课的成绩学生2的基本情况和各门功课的成绩学生1的基本情况和各门功课的成绩- 学生n的基本情况和各门功课的成绩学生2的基本情况和各门
4、功课的成绩学生1的基本情况和各门功课的成绩班级nstruct *next-null程序调用图:主函数main 函数zuoye1读入学生基本资料并保存到cond.dat中函数read将文件中的数据读入8 统计成绩并排序1录 入5 删除整个班3修改基本情况4 删除某个学生基本情况2插入6 登记成绩7 修改成绩11,12 输出当前学生的基本资料和成绩10 列出不及格人的名单9 统计各班的平均成绩三:各个函数所实现的功能zuoye1 -录入学生的基本情况zuoye2-插入某个学生的基本信息zuoye3- -修改某个学生的基本信息zuoye4-删除某个学生的基本信息zuoye5-删除某个班级的基本信息z
5、uoye6-登记各班学生各门功课的成绩zuoye7-修改各班学生各门功课的成绩zuoye8-统计每个学生的平均成绩并排序zuoye9-统计各班各门功课的平均成绩zuoye10-列出不及格学生清单show-显示当前学生情况和成绩四实验结果;(见程序运行)五:体会:做完这个c 语言程序设计的作业,我学会了很多新知识,对c语言有了更进一步的了解.开始时,我想用结构数组来做这个程序,但后来我发现用做它,修改数据和读取数据都显得很方便.于是,相比较之下,我便选择了十字链表.另外,通过对文件的使用,我了解到c语言可以对硬盘上的文件直接操作,既简单又方便.当然,编程时也会遇到一些困难,最令人头疼的莫过于程序
6、运行时出错了.有时 哪怕是一些很小的错误经常能导致难以预料到的后果,因此,编程时我尽量做到一丝不苟,不敢有丝毫疏忽.通过这次c语言编程的练习,我的编程水平有了进一步的提高,同时也使我对编程有了一个更清醒的了解和认识.六,程序清单。# include #include#include#includestruct branchnode;struct mainnode;char subj15;typedef struct char subj15; int r;sco;typedef struct long num; char name 15; char sex; int age; int m; in
7、t n; long room_num; long tele_num; sco score10; float k;stud;struct branchnode stud student; struct branchnode * next; ;struct mainnode int data; struct mainnode *trunk;struct branchnode * branch;void zuoye1(void) int flag=1,i=1,t=1,s=1; stud student; file * fp; char buf80,bup80; if(fp=fopen(a:cond.
8、dat,wb)=null) fprintf(stderr,cant open the filen); exit(-1); printf(开始输入学生基本情况:nn请输入1班学生基本情况:nn); fflush(stdin); while(flag) fprintf(stdout,下一个:学号,姓名,性别,年龄,寝室,电话n); gets(bup); fprintf(stdout,确定吗? ); gets(buf); if(buf0=n|buf0=n)printf(n);continue; fprintf(stdout,继续?(是y/否n/下一班p) ); gets(buf); if(buf0=
9、p|buf0=p) fprintf(stdout,n请输入第%d班学生基本情况:n,+s);i=0; if(buf0=n|buf0=n)i=2;flag=0; sscanf(bup,%ld%s%s%d%ld%ld,&student.num,, &student.sex,&student.age,&student.room_num,&student.tele_num); student.m=i; student.n=t; if(fwrite(&student,sizeof(stud),1,fp)!=1) fprintf(stderr,write errorn); brea
10、k; if(i=0)i=1;+t; printf(n); fclose(fp);stud * createrange(struct branchnode * * headp,file * fp) struct branchnode *p,* tail; stud student; p=(struct branchnode *)malloc(sizeof(struct branchnode); if(!feof(fp)&!ferror(fp) fread(&p-student,sizeof(stud),1,fp); p-next=null; *headp=p; tail=p; while(!fe
11、rror(fp)&p-student.m&p-student.m!=2) p=(struct branchnode*)malloc(sizeof(struct branchnode); fread(&p-student,sizeof(stud),1,fp); p-next=null; tail-next=p; tail=p; p=* headp; return(&tail-student);struct mainnode * * enter (void) stud * q; struct mainnode * mp,* head,* tail; file * fp; if(fp=fopen(a
12、:cond.dat,rb)=null) fprintf(stderr,cant open the filen); exit(-1); head=null; mp=(struct mainnode *)malloc(sizeof(struct mainnode); mp-trunk=null; mp-branch=null; head=mp; tail=mp; q=createrange(&mp-branch,fp); mp-data=q-n; while(q-m!=2) mp=(struct mainnode *)malloc(sizeof(struct mainnode); mp-branc
13、h=null; mp-trunk=null; tail-trunk=mp; tail=mp; q=createrange(&mp-branch,fp); mp-data=q-n; fclose(fp); getch(); return(&head);struct mainnode * a(struct mainnode * * headp,int x) struct mainnode * p; p=* headp; while(p-data!=x)p=p-trunk; return(p);void show(struct mainnode * * headp,int r) struct mai
14、nnode * mp; struct branchnode * p;int s; mp=*headp; while(mp!=null) p=mp-branch;printf(nclass%2d:n,p-student.n); while(p!=null) printf(%8ld%19s%3c%4d%5ld%10ldn,p-student.num,, p-student.sex,p-student.age,p-student.room_num,p-student.tele_num); if(r=0) s=0; while(sstudent.scores.subj,p-
15、student.scores.r); +s; p=p-next; printf(nn); mp=mp-trunk; void copy (struct mainnode * * head) struct mainnode * mp; struct branchnode * p;file * fp; if(fp=fopen(a:cond.dat,r+b)=null) fprintf(stderr,cant open the filen); exit(-1); mp=*head; while(mp!=null) p=mp-branch; while(p!=null) if(mp-trunk=nul
16、l&p-next=null) p-student.m=2; if(fwrite(&p-student,sizeof(stud),1,fp)!=1)fprintf(stderr,write errorn);break; p=p-next; mp=mp-trunk; fclose(fp);void zuoye2(struct mainnode * *headp) struct branchnode * current, * head,*new,*last;struct mainnode *pc; char buf80,bup5;struct branchnode * * dc;int x,flag
17、=1; while(flag) new=(struct branchnode *)malloc(sizeof(struct branchnode); fprintf(stdout,请输入插入新生所在班级的班级号:n); scanf(%d,&x); fprintf(stdout,请输入新生基本情况:学号,姓名,性别,年龄,寝室,电话n); fflush(stdin); gets(buf); fprintf(stdout,确定吗? ); gets(bup); if(bup0=n|bup0=n)printf(n);continue; sscanf(buf,%ld%s%s%d%ld%ld,&new-s
18、tudent.num,,&new-student.sex, &new-student.age,&new-student.room_num,&new-student.tele_num); new-student.n=x; new-student.m=1;pc=a(headp,x); dc=&pc-branch;head=*dc; current=head; while(new-student.numcurrent-student.num¤t-next!=null) last=current; current=current-next; if(new-s
19、tudent.numstudent.num ) if(current=head) new-next=head; *dc=new; else new-next=current; last-next=new; else new-next=null; current-next=new; current-student.m=1; if(pc-trunk!=null)new-student.m=0; else new-student.m=2; fprintf(stdout,继续?); gets(buf); if(buf0=n|buf0=n)flag=0;printf(n); void zuoye3(st
20、ruct mainnode * * headp) int flag=1,i,x;char buf80,bup5; struct branchnode *head,*p; while(flag) fprintf(stdout,请输入要修改学生所在班级的班级号:n); scanf(%d,&x); head=a(headp,x)-branch; p=head; fprintf(stdout,请输入要修改学生的学号n); scanf(%ld,&i); while(i!=p-student.num) p=p-next; fprintf(stdout,请输入要修改学生新的基本情况n); fflush(st
21、din); gets(buf); fprintf(stdout,确定吗? ); gets(bup); if(bup0=n|bup0=n)printf(n);continue; sscanf(buf,%ld%s%s%d%ld%ld,&p-student.num,, &p-student.sex,&p-student.age,&p-student.room_num,&p-student.tele_num); fprintf(stdout,继续?); gets(buf); if(buf0=n|buf0=n)flag=0; printf(n); void zuoye4(st
22、ruct mainnode * * headp) int flag=1,i,x;char buf80,bup5; struct branchnode *p,*last; struct branchnode * * head; while(flag) fprintf(stdout,请输入要删除学生所在班级的班级号:n); scanf(%d,&x); head=&a(headp,x)-branch; p=*head; fprintf(stdout,请输入要删除学生的学号n); scanf(%ld,&i); fprintf(stdout,确定吗? ); fflush(stdin); gets(bup
23、); if(bup0=n|bup0=n)printf(n);continue; while(i!=p-student.num) last=p; p=p-next; if(p-student.num=i) if(p=*head) *head=p-next; else last-next=p-next; if(p-next=null)last-student.m=0; free(p); fprintf(stdout,继续?); fflush(stdin); gets(buf); if(buf0=n|buf0=n)flag=0; printf(n); void zuoye5(struct mainn
24、ode * * headp) int x,flag=1;char bup5,buf80; struct mainnode * p,* last; while(flag) fprintf(stdout,请输入要删除班级的班级号:n); scanf(%d,&x); fprintf(stdout,确定吗? ); fflush(stdin); gets(bup); if(bup0=n|bup0=n)printf(n);continue; p=* headp; while(p-data!=x) last=p; p=p-trunk; if(p-data=x) if(p=*headp) *headp=p-t
25、runk; else last-trunk=p-trunk; free(p); fprintf(stdout,继续?); gets(buf); if(buf0=n|buf0=n)flag=0; printf(n); void zuoye6 (struct mainnode * * headp) file *fp; int flag=1,i=0,n,q;char buf80; struct mainnode *mp; struct branchnode *p; sco score10; if(fp=fopen(a:subj.dat,wb)=null) fprintf(stderr,cant op
26、en the filen); exit(-1); while(flag) fprintf(stdout,请输入第%d科科目名称:n,+i); fflush(stdin); gets(buf); sscanf(buf,%s,scorei-1.subj); if(fwrite(scorei-1.subj,sizeof(subj),1,fp)!=1) fprintf(stderr,write errorn); break; fprintf(stdout,n继续?n); gets(buf); if(buf0=n|buf0=n) flag=0; fclose(fp); fprintf(stdout,请分
27、别输入每个学生的成绩:n); mp=*headp; while(mp!=null) p=mp-branch; printf(class%dn,mp-data); while(p!=null) printf(%8ld%15s:n,p-student.num,); n=0; while(nstudent.scoren.r); strcpy(p-student.scoren.subj,scoren.subj); +n; p=p-next; mp=mp-trunk; int count(void) int n=0; char buf15;file *fp; if(fp=fo
28、pen(a:subj.dat,rb)=null) fprintf(stderr,cant open the filen); exit(-1); while(!feof(fp)&!ferror(fp) fread(buf,sizeof(buf),1,fp); +n; -n; fclose(fp); return(n);void zuoye7 (struct mainnode * * headp) int flag=1,i,x,s,t;char buf15,bup5; struct branchnode *p,*last; struct branchnode * * head; while(fla
29、g) fprintf(stdout,请输入要修改成绩学生所在班级的班级号:); scanf(%d,&x); head=&a(headp,x)-branch; p=*head; fprintf(stdout,请输入要修改成绩学生的学号:); scanf(%ld,&i); while(i!=p-student.num)p=p-next; fprintf(stdout,请输入要修改的科目名:); scanf(%s,buf); s=0; while(sstudent.scores.subj)break; +s; fprintf(stdout,请输入%s的新成绩:,buf); scanf(%d,&t);
30、 fprintf(stdout,确定吗? ); fflush(stdin); gets(bup); if(bup0=n|bup0=n)printf(n);continue; p-student.scores.r=t; fprintf(stdout,继续?); fflush(stdin); gets(buf); printf(n); if(buf0=n|buf0=n)flag=0; void zuoye8 (void) struct branchnode *p,* head; stud student,temp;int s=1,i,n;float t=0; file * fp; if(fp=fo
31、pen(a:cond.dat,rb)=null) fprintf(stderr,cant open the filen); exit(-1); head=null;i=count(); while(s!=2) p=(struct branchnode *)malloc(sizeof(struct branchnode); if(!feof(fp)&!ferror(fp) fread(&p-student,sizeof(stud),1,fp);n=0;t=0;while(nstudent.scoren.r; +n; p-student.k=t/i; p-next=head; head=p;s=p
32、-student.m; for(i=0;inext!=null;p=p-next) if(p-student.knext-student.k) temp=p-student; p-student=p-next-student; p-next-student=temp; p=head;i=0; while(p!=null) printf(n第%d名:n,+i); printf(%6ld%10s%5c%6d%7ld%10ldn,p-student.num,, p-student.sex,p-student.age,p-student.room_num,p-student.tele_num); s=0; while(sstudent.scores.subj,p-student.scores.r); +s; printf(n 平均成绩:%7.2fn,p-student.k); p=p-next; fclose(fp);void zuoye9 (struct mainnode * * headp) struct mainnode *mp;double s,t,q; int
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年度海域使用权出让与海洋渔业资源养护协议
- 2025年度矿山股权转让及矿山生态修复合作协议
- 二零二五年度合同解除赔偿调解协议
- 全新2025年度柴油运输领域竞业禁止与行业规范协议
- 二零二五年度学校学生资助项目合作协议
- 二零二五年度公益节目编排与社会责任履行协议
- 欧洲杯电视转播权合同尘埃落定
- 企业信息数据共享与保密合同
- 离婚合同书无子女财产分割协议
- 度建筑农民工施工合同范本
- GA 38-2021银行安全防范要求
- 宏观经济学 布兰查德第六版 第6章劳动力市场
- 99S203 消防水泵接合器安装图集
- 实用参考国际标准智商测试39题详细答案
- 斯瓦希里语轻松入门
- 拼音田字格(A4 word 打印版)
- 绿化养护工人配置标准
- 教育部人文社科项目申请书范本-2-副本
- GA∕T 743-2016 闪光警告信号灯
- 珍爱生命预防溺水 安全教育主题班会PPT课件
- 呼吸内科实习生出科考试试题卷与答案
评论
0/150
提交评论