学生选课系统及学籍管理.doc_第1页
学生选课系统及学籍管理.doc_第2页
学生选课系统及学籍管理.doc_第3页
学生选课系统及学籍管理.doc_第4页
学生选课系统及学籍管理.doc_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

综合设计题目: 学籍管理及选课系统 课程名称: C语言高级程序及设计学 院 : 自动化 专业班级: 12电力4班 学 号: 姓 名: 郑程鹏 联系方式: 任课老师: 王星华 2014年12月3日#include#include#includeint courcenum,studentnum;/课程的结构体struct cource int num,credit,maxnum,selectednum; char courceName30; struct cource * next;cource;/学生的结构体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();/从文件中读取已保存的学生数据 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(请输入您的选择:); scanf(%d,&i); if(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); xuankecaidan();/选课的函数 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)=NULL)/以只读的方式打开文件 /无法打开文件的时候 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-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,&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 file%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为要分解的字符串,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-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)&(*strnum,c-courceName,c-credit,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-num!=NULL) char outcource15=;for(i=0;iselectednum;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,%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=studenthead;for(j =0;j num!=NULL) char outcource15=;for(i=0;iselectednum;i+) char temp20;if(i=0)itoa(s-courcei,temp,10);strcat(outcource,temp);elsestrcat(outcource,fgzf);itoa(s-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 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(studenthead=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 num) if(studenthead=p1) studenthead=p0; else p2-next=p0; p0-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 selectednum=0; newstudent-cource0=0; printf(学号 姓名 n); scanf(%d %s,&newstudent-num,newstudent-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 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;s-courcei0;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 tuixuan(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-courcei!=num;i+) if(i=s-selectednum) printf(您还没选此课程n);goto run; for(j=i;s-courcej0;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; struct cource * c; struct student * s;for(j =0;j num!=num & s-next!=NULL) s=s-next; if(s-num!=num) printf(没有此人!n); goto end; system(cls); c=courcehead; for(j =0;j maxnum!=c-selectednum) printf(%-16d%-16s%-10d%-16d%-10dn,c-num,c-courceName,c-credit,c-maxnum,c-selectednum); j+; c=c-next; if(j=0) printf(课程已被选完n); goto end; for(j =0;j num!=num & s-next!=NULL) s=s-next; if(s-num!=num) printf(无此人n); goto end; system(cls); printf(已选课程序号:n); if(s-cource=0) printf(没选课n); goto end; for(i=0;(s-courcei0)&(icourcei); printf(n是否退课?y/n); getchar(); e=getchar(); while(e=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 selectedcredit); p = q, q = q-next); zhijiecharu = zhijiecharu-next; if (q = head) head = t; else p-next = t; t-next = q; return head;void sortstudent()struct student *newstude

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论