




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、#include<stdio.h>#include<stdlib.h>#include<string.h>int N1,N2;struct studentint num2;char name220;int nelenum50;int nelen;struct student * next;struct course/所选课程编号/所选课程学分和int num1;/课程编号char name120;char major20;char type20;int credit;int period;char teacher20;int people;struct co
2、urse *next;struct course * head1;struct student * head2;void zhang()/从键盘录入课程信息/选此门课程的人数/结构体指针struct course *p1,*p2;N1=0;p1=p2=(struct course *)malloc(sizeof(struct course);printf("课程编号t课程名称t主修t课程性质t学分t课时t教师n");scanf("%d%s%s%s%d%d%s",&p1->num1,p1->name1,p1->major,p1-&
3、gt;type,&p1->cr edit,&p1->period,p1->teacher);p1->people=0;head1=NULL;while(p1->num1!=0)N1=N1+1;if(N1=1)head1=p1;else p2->next=p1;p2=p1;p1=(struct course * )malloc(sizeof(struct course);scanf("%d%s%s%s%d%d%s",&p1->num1,p1->name1,p1->major,p1->type,
4、&p1->cr edit,&p1->period,p1->teacher);p1->people=0;p2->next=NULL;void zhang1()/从文件录入课程信息FILE * fp;char filepath20;struct course *p1,*p2;N1=0;printf(" 请输入您要读取的路径:");getchar();gets(filepath);if(fp=fopen(filepath,"r")=NULL)printf(" 找不到 %s 文件 !n",file
5、path);exit(0);p1=p2=(struct course*)malloc(sizeof(struct course);fscanf(fp,"%d%s%s%s%d%d%s%d",&p1->num1,p1->name1,p1->major,p1->type,& p1->credit,&p1->period,p1->teacher,&p1->people);while(!feof(fp)N1=N1+1;if(N1=1)head1=p1;elsep2->next=p1;p2=p1;p1
6、=(struct course * )malloc(sizeof(struct course);fscanf(fp,"%d%s%s%s%d%d%s%d",&p1->num1,p1->name1,p1->major,p1->type,& p1->credit,&p1->period,p1->teacher,&p1->people);p2->next=NULL;void load()/录入课程信息函数int i;printf("ttt 录入课程信息 n");printf(&
7、quot;n1. 从键盘录入");printf("n2. 从文件录入");printf("n3. 返回主菜单n");printf(" 请选择 1-3:");scanf("%d",&i);switch(i)case 1: zhang(); break;case 2:zhang1();break;case 3:break;void insert(struct course *incourse)/增加课程信息struct course *p0,*p1,*p2;p1=head1;p0=incourse;i
8、f(head1=NULL)head1=p0;p0->next=NULL;elsewhile(p0->num1>p1->num1) && (p1->next!=NULL)p2=p1;p1=p1->next;if(p0->num1<=p1->num1)if(head1=p1)head1=p0;elsep2->next=p0;p0->next=p1;elsep1->next=p0;p0->next=NULL;N1=N1+1;void delc(int num1)/ 删除课程信息struct course *
9、p1,*p2;if(head1=NULL)printf("n 无法删除 !n");goto end;p1=head1;while(num1!=p1->num1 && p1->next!=NULL)p2=p1;p1=p1->next;if(num1=p1->num1)if(p1=head1)head1=p1->next;elsep2->next=p1->next;printf(" 已删除 n");N1=N1-1;elseprintf(" 没有此课程n");end:;void ma
10、nagementc()/课程信息管理函数struct course * p1;int i,num1;printf("ttt 课程信息管理n");printf("1. 添加课程n");printf("2. 删除课程n");printf("3. 返回 n");printf(" 请输入1-3:n");scanf("%d",&i);switch(i)case 1:p1=(struct course *)malloc(sizeof(struct course);printf(&
11、quot;课程编号t课程名称t主修t课程性质t学分t课时t教师n");scanf("%d%s%s%s%d%d%s",&p1->num1,p1->name1,p1->major,p1->type,&p1->cr edit,&p1->period,p1->teacher);p1->people=0;insert(p1); break;case 2:printf("请输入您要删除的课程编号:n");scanf("%d",&num1);delc(num1
12、); break;case 3:break;void putin(void) /从键盘录入学生信息int i;struct student *p1,*p2;N2=0;p1=p2=(struct student *)malloc(sizeof(struct student);printf("学号 t 姓名 n");scanf("%d%s",&p1->num2,p1->name2);p1->nelen=0;for(i=0;i<20;i+) p1->nelenumi=0;head2=NULL;while(p1->nu
13、m2!=0)N2=N2+1;if(N2=1)head2=p1;elsep2->next=p1;p2=p1;p1=(struct student * )malloc(sizeof(struct student);scanf("%d%s",&p1->num2,p1->name2);p1->nelen=0;for(i=0;i<20;i+) p1->nelenumi=0;p2->next=NULL;void putin2()/从文件录入学生信息int i=0;FILE * fp;char filepath20;struct stud
14、ent *p1,*p2;N2=0;printf("请输入您要读取的路径:”);getchar();gets(filepath);if(fp=fopen(filepath,"rt")=NULL)printf(" 找不到 %s 文件 !n",filepath);exit(0);p1=p2=(struct student*)malloc(sizeof(struct student);fread(p1,sizeof(struct student),1,fp);head2=NULL;while(!feof(fp)i=0;N2=N2+1;if(N2=1)h
15、ead2=p1;elsep2->next=p1;p2=p1;p1=(struct student * )malloc(sizeof(struct student); fread(p1,sizeof(struct student),1,fp);p2->next=NULL;void input()/录入学生信息函数int i;printf("ttt 录入学生信息 n");printf("n1. 从键盘录入 n");printf("2. 从文件录入n");printf("3. 返回主菜单n");printf(
16、" 请输入 1-3:n");scanf("%d",&i);switch(i)case 1:putin();break;case 2:putin2();break;case 3:break;void inserts(struct student * incouse)/增加学生信息struct student *p0,*p1,*p2;p1=head2;p0=incouse;if(head2=NULL)head2=p0;p0->next=NULL;elsewhile(p0->num2>p1->num2) && (
17、p1->next!=NULL)p2=p1;p1=p1->next;if(p0->num2 <= p1->num2)if(head2=p1) head2=p0; else p2->next=p0;p0->next=p1;elsep1->next=p0;p0->next=NULL;N2=N2+1;void dels(int num2)/ 删除学生信息struct student *p1,*p2;if(head2=NULL)printf("n 无法删除 n");goto end;p1=head2;while(num2!=p1-
18、>num2 && p1->next!=NULL) p2=p1;p1=p1->next;if(num2=p1->num2)if(p1=head2)head2=p1->next;elsep2->next=p1->next;printf(" 已删除 n");N2=N2-1;elseprintf(" 没有此学生编号n");end:;void managements()/学生信息管理函数struct student * p1;int i,num2;printf("ttt 学生信息管理n"
19、);printf("1.添加学生信息n");printf("2. 删除学生信息n");printf("3. 返回主菜单n");printf(" 请选择 1-3:n");scanf("%d",&i);switch(i)case 1:p1=(struct student *)malloc(sizeof(struct student);p1->nelen=0;p1->nelenum0=0;printf("numtnamen");scanf("%d%s&
20、quot;,&p1->num2,p1->name2);inserts(p1);break;case 2:printf("请输入您要删除的学生编号:n");scanf("%d",&num2);dels(num2); break;case 3:break;/学生选课void elect() struct student * s;struct course * p;int a,i,b;printf("请输入您的学号:n");scanf("%d",&a);s=head2;while(s-
21、>num2)!=a&&s->next!=NULL) s=s->next;if(s->num2!=a)printf(" 您的信息不存在,请重新输入 :n");goto end;if(s->nelen)>10)printf(" 您的学分已满");goto end;printf("请输入您要选修的课程编号n");scanf("%d",&b);for(i=0;(s->nelenumi)=0;i+);s->nelenumi=b;p=head1;while
22、(p->num1)!=b)p=p->next;for(i=0;(s->nelenumi)!=0;i+);s->nelenumi=b;(p->people)+;(s->nelen)=(s->nelen)+(p->credit);(p->people)+;end:;void back()/学生退课struct student * p;struct course * p1;int b,i,j,a;printf("请输入您的学号:n");scanf("%d",&a);p=head2;while(p-&
23、gt;num2!=a&&p!=NULL) p=p->next;if(p=NULL)printf(" 您的信息不存在:n");elseprintf(" 请输入您要退选的课程:n");scanf("%d",&b);p1=head1;while(p1->num1!=b) p1=p1->next;for(i=0;p->nelenumi!=b;i+);for(j=i;p->nelenumj!=0;j+)p->nelenumj=p->nelenumj+1;p->nelenum
24、-j=0;(p->nelen)=(p->nelen)-(p1->credit);(p1->people)-;printf("succeed!n");void elective()/学生选课信息管理int i;printf("ttt 学生选课信息管理n");printf("1. 选课 n");printf("2. 退课 n");printf("3. 返回主菜单n");printf(" 请输入 1-3:n");scanf("%d",&a
25、mp;i);switch(i)case 1:elect();break;case 2:back();break;case 3:break;void listc()/浏览课程信息struct course * p;p=head1;printf(" 课程编号课程名称主修 课程性质学分 课时教师 选课人数 n");while(p!=NULL)printf("%6d%13s%13s%10s%7d%7d%12s%5dn",p->num1,p->name1,p->major, p->type,p->credit,p->period
26、,p->teacher,p->people);p=p->next;void lists()/浏览学生信息struct student * p;int a;p=head2;所选课程学分n");printf("学生编号学生姓名所选课程编号while(p!=NULL)printf("%6d%13s",p->num2,p->name2);printf("%6d",p->nelen);for(a=0;p->nelenuma!=0&&a<14;a+) printf("%d&
27、quot;,p->nelenuma);printf("n");p=p->next;void intoc()/存储课程信息FILE * fp;struct course * p;char filepath30;printf(" 输入路径 :");getchar();gets(filepath);if(fp=fopen(filepath,"w")=NULL)无法储存 !");exit(0);p=head1;while(p!=NULL)fprintf(fp,"%d%s%s%s%d%d%s%dn",p
28、->num1,p->name1,p->major,p->type,p->credit,p->period,p->teacher,p->people);p=p->next;fclose(fp);printf(" 已储存入 %s 文件 !n",filepath);void intos()/存储学生信息FILE * fp;struct student * p;char filepath30;printf("请输入路径:");getchar();gets(filepath);if(fp=fopen(filep
29、ath,"wt")=NULL)printf("n 无法储存 !");exit(0);p=head2;while(p!=NULL)fwrite(p,sizeof(struct student),1,fp);p=p->next;fclose(fp);printf(" 已储存入 %s 文件 !n",filepath);void into()/信息存储函数printf("ttt 信息存储 n");printf("1.课程信息存储n");printf("2. 学生信息存储 tn"
30、);printf("3. 返回主菜单n");printf("请输入 1-3n");scanf("%d",&i);switch(i)case(1):intoc();break;case(2):intos();break;case(3):break;/信息存储浏览函数void store()int i;printf("tt 信息存储和浏览n");printf("1.课程信息浏览n");printf("2. 学生信息浏览n");printf("3. 信息存储 n&
31、quot;);printf("4. 返回主菜单n");printf(" 请输入1-4:n");scanf("%d",&i);switch(i)case(1):listc();break;case(2):lists();break;case(3):into();break;case(4):break;/按学生编号查找学生信息void search1() int a,b;struct student * p;printf("请输入学生编号”);scanf("%d",&a);p=head2;pr
32、intf("学号学生姓名所选课程编号所选课程学分n");while(p!=NULL)if(p->num2=a)printf("%6d%13s ",p->num2,p->name2);for(b=0;p->nelenumb!=0&&b<14;b+)printf("%d",p->nelenumb);printf("%10dn",p->nelen);p=p->next;void search2()/按学生姓名查找学生信息int b;char name20;s
33、truct student * p;printf("请输入要查找的学生姓名:");scanf("%s",name);p=head2;printf("学号学生姓名所选课程编号所选课程学分n");while(p!=NULL)if(strcmp(name,p->name2)=0)printf("%6d%13s ",p->num2,p->name2);for(b=0;p->nelenumb!=0&&b<14;b+) printf("%d",p->nel
34、enumb);printf("%10dn",p->nelen);p=p->next;void search()/学生信息查找主函数int i;printf("ttt 学生信息查找");printf("n1. 按学号查找");printf("n2. 按姓名查找");printf("n3. 返回主菜单");printf("n 请输入 1-3:");scanf("%d",&i);switch(i)case 1:search1();break;case 2:search2();break;case 3:break;void main()/主函数char m;int i
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 提高肝功能的保健方法
- 白内障手术患者的健康教育
- 高浓度荧光假单胞菌RHBA17对马铃薯植株的生长抑制研究
- 复荣通脉胶囊对瘀血内停型原发性高血压靶器官中心血管保护作用
- 父母教育对孩子的影响
- 高中生英语听觉词汇知识英语语音意识与英语听力理解的关系研究
- 2024年宁德寿宁县招聘教师笔试真题
- 2025年钴基及钴镍基合作协议书
- 2025年电气化铁路架空导线合作协议书
- 医院餐公室半年述职报告
- DL5168-2023年110KV-750KV架空输电线路施工质量检验及评定规程
- 工资条(标准模版)
- 皮肤科常用护理技术操作规程
- 第四讲 搜索引擎检索
- 四川省中小流域暴雨洪水计算表格(尾矿库洪水计算)
- 新视野大学英语(第三版)读写教程Book4-Unit7-Section-B-A-worldwide-food-crisis课件
- 毛笔字练习基本笔画及毛笔字基本笔画入门
- 《广东省建筑与装饰工程综合定额2023》
- Overture 4.0 中文版使用手册(V1.0)-IT计算机-专业资料
- 带括号的方程计算题100道
- 水库移民安置档案分类大纲与编号方案
评论
0/150
提交评论