C语言学生选课统.docVIP

  • 9
  • 0
  • 约 16页
  • 2016-10-22 发布于贵州
  • 举报
#includestdio.h #includestdlib.h int N1,N2,kk1,kk2,kk3; struct couse * head1; struct student * head2; struct couse//课程信息结构体 { int num1; char name1[20]; int score; int nelepeo;//课程已选人数 int Melepeo;//课程人数上限 struct couse * next; }; struct student//学生信息结构体 { int num2; char name2[20]; int nelenum[50];//已选课程编号 int nelen;//已选课程数量 struct student * next; }; void Ms() { for(kk1=0;kk11100;kk1++) for(kk2=0;kk21200;kk2++) for(kk3=0;kk31200;kk3++); } void keyboardc()//录入课程子函数(从键盘录入) { struct couse *p1,*p2; N1=0; p1=p2=(struct couse*)malloc(sizeof(struct couse)); printf(课程编号\t课程名称\t学分\t课程人数上限\n); scanf(%d%s%d%d,p1-num1,p1-name1,p1-score,p1-Melepeo); p1-nelepeo=0; head1=NULL; while(p1-num1!=0) { N1=N1+1; if(N1==1)head1=p1; else p2-next=p1; p2=p1; p1=(struct couse * )malloc(sizeof(struct couse)); scanf(%d%s%d%d,p1-num1,p1-name1,p1-score,p1-Melepeo); p1-nelepeo=0; } p2-next=NULL; } void filec()//录入键盘子函数(从文件录入) { FILE * fp; char filepath[20]; struct couse *p1,*p2; N1=0; printf(输入要读入的文件路径:); getchar(); gets(filepath); if((fp=fopen(filepath,r))==NULL) { printf(找不到%s文件!\n,filepath); exit(0); } p1=p2=(struct couse*)malloc(sizeof(struct couse)); fscanf(fp,%d%s%d%d%d,p1-num1,p1-name1,p1-score,p1-nelepeo,p1-Melepeo); head1=NULL; while(!feof(fp)) { N1=N1+1; if(N1==1)head1=p1; else p2-next=p1; p2=p1; p1=(struct couse * )malloc(sizeof(struct couse)); fscanf(fp,%d%s%d%d%d,p1-num1,p1-name1,p1-score,p1-nelepeo,p1-Melepeo); } p2-next=NULL; } void inputc()//录入课程主函数 { int i; printf(\t\t\t录入课程信息\n); printf(\n1.从键盘录入\n); printf(2.从文件录入\n); printf(3.返回主菜单\n); printf(请选择(1~3):\n); scanf(%d,i); switch(i) { case(1):keyboardc();break; case(2):filec();break; case(3):break; } } void insertc(struct couse *incou

文档评论(0)

1亿VIP精品文档

相关文档