版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 综合设计题目: 学籍管理及选课系统 课程名称: C语言高级程序及设计学 院 : 自动化 专业班级: 12电力4班 学 号: 姓 名: 郑程鹏 联系方式: 任课老师: 王星华 2014年12月3日#include<stdio.h>#include<stdlib.h>#include<string.h>int courcenum,studentnum;/课程的结构体struct cource int num,credit,maxnum,selectednum; char courceName30; struct cource * next;cource;/学生
2、的结构体struct student char studentname20; int selectednum,selectedcredit,num; int cource10; struct student * next;student;/指针链表的头struct cource * courcehead;struct student * studenthead;int j;void main() void getcource(); void getstudent(); int i;/作为获取用户的输入的变量 getcource();/从文件中读取已保存的课程数据getstudent();/从文
3、件中读取已保存的学生数据 system("cls");run: for(j =0;j < 80;j+) printf("*"); printf("nnn1.查看课程 "); printf("2.查看管理学生 "); printf("3.查看选课 ");printf("4.选课情况 "); printf("5.退出系统 nnn"); for(j =0;j < 80;j+) printf("*"); printf("请
4、输入您的选择:"); scanf("%d",&i); if(i < 1 | i > 5) printf(" 输入有误n"); goto run; if(i = 1) system("cls");/清屏函数,清楚屏幕所有的东西 viewcource();/查看课程的函数 goto run; else if(i = 2) system("cls"); manage();/管理学生的函数 goto run; else if(i = 3) system("cls"); xu
5、ankecaidan();/选课的函数 goto run; else if(i = 4) system("cls"); sortstudent();/查看选课情况的函数 goto run; else if(i = 5) system("cls"); void getcource() FILE * fp; struct cource *p1,*p2; courcenum=0;char filepath = "cource.txt"/默认txt文件在当前目录下 if(fp=fopen(filepath,"r")=NUL
6、L)/以只读的方式打开文件 /无法打开文件的时候 printf("error to find cource file%s!n",filepath); exit(0); /生成struct cource大小的内存并让p1,p2指向 p1=p2=(struct cource*)malloc(sizeof(struct cource); /从文件中读取 fscanf(fp,"%d%s%d%d%d",&p1->num,p1->courceName,&p1->credit,&p1->maxnum,&p1-&g
7、t;selectednum); courcehead=NULL; while(!feof(fp)/循环读取直到读到文件结尾 courcenum=courcenum+1; /读取第一个课程的时候情况不同 if(courcenum=1) courcehead=p1; else p2->next=p1; p2=p1; p1=(struct cource * )malloc(sizeof(struct cource); fscanf(fp,"%d%s%d%d%d",&p1->num,p1->courceName,&p1->credit,&am
8、p;p1->maxnum,&p1->selectednum); p2->next=NULL;void getstudent() char bianhao20;char * fgzf = ""char * cba;int i;FILE * fp; struct student *p1,*p2; courcenum=0;char filepath = "student.txt" if(fp=fopen(filepath,"r")=NULL) printf("error to find student f
9、ile%s!n",filepath); exit(0); p1=p2=(struct student*)malloc(sizeof(struct student); fscanf(fp,"%d%s%d%s%d",&p1->num,p1->studentname,&p1->selectednum,bianhao,&p1->selectedcredit);cba=strtok(bianhao,fgzf);/char *strtok(char s, const char *delim);分解字符串为一组字符串。s为要分解的
10、字符串,delim为分隔符字符串。i=0;while(cba) p1->courcei=change(cba);cba=strtok(NULL,fgzf);i+;studenthead=NULL; while(!feof(fp) studentnum=studentnum+1; if(studentnum=1) studenthead=p1; else p2->next=p1; p2=p1; p1=(struct student * )malloc(sizeof(struct student); fscanf(fp,"%d%s%d%s%d",&p1-&g
11、t;num,p1->studentname,&p1->selectednum,bianhao,&p1->selectedcredit);cba=strtok(bianhao,fgzf);i=0;while(cba) p1->courcei=change(cba);cba=strtok(NULL,fgzf);i+; p2->next=NULL;int change(char *str) int v=0; do v=10*v+*str-'0' str+; while(*str>='0')&&(*st
12、r<='9'); return v;void setcource() FILE * fp; struct cource * c; char filepath = "cource.txt" if(fp=fopen(filepath,"w")=NULL) printf("nfail"); exit(0); c=courcehead; while(c!=NULL) fprintf(fp,"%dt%st%dt%dt%dn",c->num,c->courceName,c->credit
13、,c->maxnum,c->selectednum); c=c->next; fclose(fp);void setstudent() FILE * fp; struct student * s; char filepath = "student.txt" if(fp=fopen(filepath,"w")=NULL) printf("nnot save"); exit(0); char fgzf2=""int i;s=studenthead;while(s!=NULL && s-
14、>num!=NULL) char outcource15=""for(i=0;i<s->selectednum;i+) char temp20;if(i=0) itoa(s->courcei,temp,10);strcat(outcource,temp);else strcat(outcource,fgzf);itoa(s->courcei,temp,10);strcat(outcource,temp);if(s->selectednum=0)strcat(outcource,"0");fprintf(fp,"
15、;%dt%st%dt%st%dn",s->num,s->studentname,s->selectednum,outcource,s->selectedcredit);s=s->next; fclose(fp); printf("okn",filepath);void save() setcource();setstudent();void viewstudent() struct student * s;char fgzf2=""int i;system("cls");s=studenthea
16、d;for(j =0;j < 80;j+) printf("*");printf("学号 姓名 已选课程数 已选课程序号 总学分n");while(s!=NULL && s->num!=NULL) char outcource15=""for(i=0;i<s->selectednum;i+) char temp20;if(i=0)itoa(s->courcei,temp,10);strcat(outcource,temp);elsestrcat(outcource,fgzf);itoa(s
17、->courcei,temp,10);strcat(outcource,temp);printf("%-16d%-16s%-16d%-16s%-10dn",s->num,s->studentname,s->selectednum,outcource,s->selectedcredit);s=s->next;for(j =0;j < 80;j+) printf("*");void viewcource() system("cls"); struct cource * c;c=courcehead
18、;printf("课程序号 课程名称 学分 最大人数 已选人数n");while(c!=NULL) printf("%-16d%-16s%-10d%-16d%-10dn",c->num,c->courceName,c->credit,c->maxnum,c->selectednum);c=c->next;void zengjia(struct student * newstudent) struct student *p0,*p1,*p2; p1=studenthead; p0=newstudent; if(stude
19、nthead=NULL) studenthead=p0; p0->next=NULL; else while(p0->num > p1->num) && (p1->next!=NULL) p2=p1; p1=p1->next; if(p0->num = p1->num) printf("您所输入的学号重复n");goto end; if(p0->num < p1->num) if(studenthead=p1) studenthead=p0; else p2->next=p0; p0-&
20、gt;next=p1; else p1->next=p0; p0->next=NULL; studentnum=studentnum+1;save();end: ;void manage() struct student * newstudent; int i,num;run: for(j =0;j < 80;j+) printf("*"); printf("1.添加新学生n");printf("2.查看已存在的学生资料n"); printf("3.返回n"); for(j =0;j < 8
21、0;j+) printf("*"); scanf("%d",&i); if(i = 1) system("cls"); newstudent=(struct student *)malloc(sizeof(struct student); newstudent->selectednum=0; newstudent->cource0=0; printf("学号 姓名 n"); scanf("%d %s",&newstudent->num,newstudent-&g
22、t;studentname); newstudent->selectedcredit=0; zengjia(newstudent); system("cls"); goto run; else if(i = 2) viewstudent(); goto run; else if(i = 3) system("cls"); void xuanke(struct student * s) struct cource * c; int num,i,j=0;run: for(j =0;j < 80;j+) printf("*");
23、 printf("请输入课程序号,返回请输入9.n");scanf("%d",&num);if(num=0) goto end;c=courcehead;while(c->num!=num && c->next!=NULL) c=c->next;if(c->num!=num) printf("输入有误n");goto run;if(c->maxnum=c->selectednum) printf("该课程人数已爆满n");goto run;for(i=0;
24、s->courcei>0;i+) if(num=s->courcei) printf("不能重复选课n"); goto run; if(s->selectednum>=5) printf("所选课程数已达5门n"); goto end;s->courcei=num;/刷新数据 (s->selectednum)+;s->selectedcredit+=c->credit;(c->selectednum)+;save();printf("选课成功n");end:;void tui
25、xuan(struct student * s) struct cource * c; int num,i,j=0;run:printf("课程序号(返回请按9回车):n"); scanf("%d",&num);if(num=9) goto end; c=courcehead;while(c->num!=num && c->next!=NULL) c=c->next;if(c->num!=num) printf("输入有误n");goto run;for(i=0;s->cource
26、i!=num;i+) if(i>=s->selectednum) printf("您还没选此课程n");goto run; for(j=i;s->courcej>0;j+) s->courcej=s->courcej+1; s->cource-j=0;s->selectednum-;s->selectedcredit-=c->credit;(c->selectednum)-;save(); printf("已退选该课程n");end:;void chaxunkexuan() char e;
27、 struct cource * c; struct student * s;for(j =0;j < 80;j+) printf("*"); int num,j=0; system("cls"); printf("请输入学号:n"); scanf("%d",&num); system("cls"); s=studenthead; while(s->num!=num && s->next!=NULL) s=s->next; if(s->num
28、!=num) printf("没有此人!n"); goto end; system("cls"); c=courcehead; for(j =0;j < 80;j+) printf("*"); printf("可选课程:n");printf("序号 课程 学分 人数上限 已选人数n"); while(c!=NULL) if(c->maxnum!=c->selectednum) printf("%-16d%-16s%-10d%-16d%-10dn",c->
29、;num,c->courceName,c->credit,c->maxnum,c->selectednum); j+; c=c->next; if(j=0) printf("课程已被选完n"); goto end; for(j =0;j < 80;j+) printf("*"); printf("n是否选课y/n?:n"); getchar(); e=getchar(); while(e='y') xuanke(s); printf("n继续选课y/n?:n");
30、 getchar(); e=getchar(); system("cls"); end:;void chaxunyixuan() char e; struct student * s; int num,i; system("cls"); printf("请输入学号:n"); scanf("%d",&num); s=studenthead; while(s->num!=num && s->next!=NULL) s=s->next; if(s->num!=num) pr
31、intf("无此人n"); goto end; system("cls"); printf("已选课程序号:n"); if(s->cource=0) printf("没选课n"); goto end; for(i=0;(s->courcei>0)&&(i<5);i+) printf("%dn",s->courcei); printf("n是否退课?y/n"); getchar(); e=getchar(); while(e=
32、9;y') tuixuan(s); printf("n继续退课?y/n"); getchar(); e=getchar(); system("cls"); end:;struct student *sort(struct student *head) struct student *zhijiecharu; struct student *t; struct student *p; struct student *q;zhijiecharu = head->next; head->next = NULL;while (zhijiecharu != NULL) for (t = zhijiecharu, q = head; (q!= NULL) && (q->selectedcredit < t->selectedcredit); p = q, q = q->next); zhijiecharu = zhijiecharu->next; if (q = head) head = t; else p->next = t; t->next
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- T/CSTEA 00010-2020九龙大白茶 白茶
- T/ZFIDA 0002-2024面向网络攻击的银行安全能力评估指南
- T/HEESA 0002-2025电力信息系统网络安全等级保护测评报告评审指南
- T/CIECCPA 020-2024二氧化碳捕集、运输与封存工艺技术规范
- T/CAPS 024-2025无人机电池性能检测设备技术要求
- T/CSBM 0050.3-2024创面修复材料有效性评价 第3部分:刺激因子屏蔽评价方法
- 2025~2026学年辽宁大连市沙河口区北师大版五年级上册数学阶段学情自测卷【附答案】
- 2025~2026学年广东省广州市从化区人教版六年级上册自主练习二数学试卷【附答案】
- 2025-2026学年湖南省张家界市初中历史八年级期末下册评估压轴试题(详细参考解析)
- PHP+HTML高频面试题及详细答案(真实职场版)
- 2026年继续教育公需课考试试题及答案
- 培训课件 -联想AAR意识 Lenovo AAR Awareness -AAR复盘资料
- 监理单位资料培训课件
- 公辅设施设备管理制度
- 《慢性阻塞性肺疾病》课件
- 消防队伍有限空间救援管理制度
- 企业级MOM系统开发合同
- 源网荷储一体化零碳智慧产业园项目可行性研究报告模板-立项拿地
- (新)患者用药指导全国知识技能竞赛基础题库(精简300题)
- (高清版)JTG 2112-2021 城镇化地区公路工程技术标准
- 飞飞自动打怪脚本
评论
0/150
提交评论