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

下载本文档

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

文档简介

1、综合设计题目:学籍管理及选课系统课程名称: C语言高级程序及设计学 院 :自动化 专业班级: 12电力4班学 号:姓 名:郑程鹏联系方式:任课老师:王星华2014年12月3日include<stdio。h#include<stdlib。hincludestring.hintcourcenum,studentnum;/课程的结构体structcourceintnum,credit,maxnum,selectednum;charcourceName30;structcource * next;cource;/学生的结构体struct studentcharstudentname20;i

2、ntselectednum,selectedcredit,num;intcource10;struct student next;student;/指针链表的头structcource * courcehead;struct student * studenthead;int j;void main()voidgetcource();voidgetstudent();inti;/作为获取用户的输入的变量getcource();/从文件中读取已保存的课程数据getstudent();/从文件中读取已保存的学生数据system("cls”);run:for(j =0;j 80;j+) p

3、rintf("*”);printf("nnn1.查看课程 ”);printf("2。查看管理学生 ”);printf(”3。查看选课 ");printf(”4。选课情况 ");printf(”5。退出系统 nnn");for(j =0;j < 80;j+) printf(”*”);printf("请输入您的选择:");scanf("%d",i);if(i 1 | i 5) printf(" 输入有误n”);goto run; if(i = 1) system(”cls”);/清屏

4、函数,清楚屏幕所有的东西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"); voidgetcource() FILE * fp;structcourc

5、e *p1,*p2;courcenum=0;char filepath = ”cource。txt”;/默认txt文件在当前目录下 if((fp=fopen(filepath,"r”))=NULL)/以只读的方式打开文件 /无法打开文件的时候printf("error to find courcefiles!n”,filepath);exit(0); /生成structcource大小的内存并让p1,p2指向 p1=p2=(structcource*)malloc(sizeof(structcource)); /从文件中读取 fscanf(fp,”%d%s%ddd"

6、;,p1num,p1courceName,p1credit,p1maxnum,&p1selectednum);courcehead=NULL;while(!feof(fp))/循环读取直到读到文件结尾 courcenum=courcenum+1; /读取第一个课程的时候情况不同if(courcenum=1) courcehead=p1;else p2>next=p1; p2=p1; p1=(structcource )malloc(sizeof(structcource)); fscanf(fp,”dsddd",p1-num,p1-courceName,p1credit

7、,p1>maxnum,p1selectednum); p2next=NULL;voidgetstudent()charbianhao20;char * fgzf = ”;";char cba;inti;FILE fp;struct student *p1,p2;courcenum=0;charfilepath = ”student.txt”;if(fp=fopen(filepath,”r”)=NULL) printf(”error to find student files!n",filepath);exit(0); p1=p2=(struct student)mal

8、loc(sizeof(struct student));fscanf(fp,"d%sds%d”,p1>num,p1studentname,&p1->selectednum,bianhao,&p1selectedcredit);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+;st

9、udenthead=NULL;while(!feof(fp) studentnum=studentnum+1;if(studentnum=1) studenthead=p1;else p2next=p1; p2=p1; p1=(struct student )malloc(sizeof(struct student));fscanf(fp,”d%s%d%sd",&p1>num,p1studentname,p1selectednum,bianhao,p1selectedcredit);cba=strtok(bianhao,fgzf);i=0;while(cba) p1co

10、urcei=change(cba);cba=strtok(NULL,fgzf);i+; p2-next=NULL;int change(char str)int v=0;do v=10v+str-0'str+; while((str=0')&(str<=9);return v;voidsetcource() FILE fp;structcource * c;charfilepath = ”cource。txt";if((fp=fopen(filepath,"w")=NULL) printf(”nfail");exit(0);

11、 c=courcehead;while(c!=NULL) fprintf(fp,"dtst%dt%dtdn",c->num,ccourceName,ccredit,c->maxnum,c>selectednum); c=c-next; fclose(fp);voidsetstudent() FILE fp;struct student s;charfilepath = ”student.txt”;if(fp=fopen(filepath,"w”))=NULL) printf("nnot save”);exit(0); charfgzf2

12、=”;";inti;s=studenthead;while(s!=NULL & s>num!=NULL)charoutcource15=”";for(i=0;is>selectednum;i+)char temp20;if(i=0)itoa(s>courcei,temp,10);strcat(outcource,temp);elsestrcat(outcource,fgzf);itoa(scourcei,temp,10);strcat(outcource,temp);if(s-selectednum=0)strcat(outcource,”0”);

13、fprintf(fp,”dt%st%dt%stdn”,s->num,sstudentname,s>selectednum,outcource,sselectedcredit);s=s->next;fclose(fp);printf(”okn",filepath);void save()setcource();setstudent();voidviewstudent()struct student * s;charfgzf2=";”;inti;system("cls");s=studenthead;for(j =0;j < 80;j

14、+) printf("”);printf(”学号姓名已选课程数已选课程序号总学分n”);while(s!=NULL & snum!=NULL)charoutcource15="”;for(i=0;isselectednum;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%1

15、6d16s%10dn”,s-num,sstudentname,s->selectednum,outcource,s>selectedcredit);s=snext;for(j =0;j < 80;j+) printf(”);voidviewcource()system(”cls”);structcource c;c=courcehead;printf(”课程序号课程名称学分最大人数已选人数n");while(c!=NULL) printf(”16d-16s10d16d10dn",c-num,c>courceName,ccredit,cmaxnum,c

16、-selectednum);c=c-next;voidzengjia(struct student * newstudent)struct student p0,p1,*p2; p1=studenthead; p0=newstudent;if(studenthead=NULL) studenthead=p0; p0>next=NULL; else while(p0num > p1-num) (p1->next!=NULL) p2=p1; p1=p1next; if(p0>num = p1num)printf("您所输入的学号重复n");goto en

17、d;if(p0num p1>num) if(studenthead=p1)studenthead=p0;else p2next=p0; p0next=p1; else p1-next=p0; p0>next=NULL; studentnum=studentnum+1;save();end: ;void manage()struct student * newstudent;inti,num;run:for(j =0;j 80;j+) printf(”");printf(”1.添加新学生n”);printf(”2。查看已存在的学生资料n”);printf(”3。返回n”);

18、for(j =0;j 80;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”,newstudentnum,newstudent>studentname);newstudentselectedcredit=0;zengjia(new

19、student);system(”cls”);goto run; else if(i = 2) viewstudent();goto run; else if(i = 3) system(”cls”); voidxuanke(struct student * s)structcource * c;intnum,i,j=0;run:for(j =0;j 80;j+) printf(”*”);printf(”请输入课程序号,返回请输入9。n”);scanf("%d”,num);if(num=0)goto end;c=courcehead;while(cnum!=num c-next!=N

20、ULL) c=c>next;if(c>num!=num)printf("输入有误n”);goto run;if(c>maxnum=cselectednum)printf(”该课程人数已爆满n”);goto run;for(i=0;scourcei0;i+)if(num=scourcei)printf(”不能重复选课n”);goto run; if(s-selectednum=5)printf("所选课程数已达5门n");goto end;s>courcei=num;/刷新数据 (sselectednum)+;sselectedcredit+

21、=ccredit;(cselectednum)+;save();printf(”选课成功n”);end:;voidtuixuan(struct student s)structcource c;intnum,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=cnext;if(c->num!=num)printf(”输入有误n”);goto ru

22、n;for(i=0;scourcei!=num;i+)if(i>=sselectednum)printf(”您还没选此课程n”);goto run;for(j=i;s-courcej0;j+)s>courcej=scourcej+1;s>cource-j=0;s->selectednum-;sselectedcredit=c-credit;(c>selectednum)-;save();printf(”已退选该课程n”);end:;voidchaxunkexuan()char e;structcource * c;struct student s;for(j =0

23、;j 80;j+) printf(”);intnum,j=0;system(”cls”);printf("请输入学号:n”);scanf("d”,num);system("cls”); s=studenthead;while(s>num!=num s->next!=NULL) s=s-next;if(snum!=num) printf(”没有此人!n”);goto end; system(”cls”); c=courcehead;for(j =0;j < 80;j+) printf("”);printf(”可选课程:n");p

24、rintf(”序号课程学分人数上限已选人数n”);while(c!=NULL) if(c>maxnum!=c-selectednum) printf(”-16d16s%-10d-16d%10dn”,c-num,c-courceName,c>credit,c-maxnum,cselectednum);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

25、);printf(”n继续选课y/n?:n");getchar(); e=getchar(); system("cls”);end:;voidchaxunyixuan()char e;struct student s;intnum,i;system(”cls”);printf(”请输入学号:n”);scanf(”d",num); s=studenthead;while(snum!=num snext!=NULL) s=s-next;if(s>num!=num) printf(”无此人n");goto end; system(”cls");

26、printf(”已选课程序号:n”);if(s>cource=0) printf("没选课n”);goto end; for(i=0;(scourcei0)&(i5);i+) printf(”%dn”,s->courcei); 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 s

27、tudent head)struct student *zhijiecharu;struct student t;struct student *p;struct student *q;zhijiecharu = head-next;headnext = NULL;while (zhijiecharu != NULL) for (t = zhijiecharu, q = head; ((q!= NULL) && (q->selectedcredit tselectedcredit); p = q, q = q-next);zhijiecharu = zhijiecharu>next;if (q = head) head = t; else pnext = t; t->next =

温馨提示

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

最新文档

评论

0/150

提交评论