#include<stdio.h>
#include<stdlib.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;kk1<1100;kk1++)
for(kk2=0;kk2<1200;kk2++)
for(kk3=0;kk3<1200;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 *incouse)//课程管理子函数(增加课程)
{
struct couse *p0,*p1,*p2;
p1=head1;
p0=incouse;
if(head1==NULL)
{
head1=p0;
p0->next=NULL;
}
else
{
while((p0->num1 > p1->num1) && (p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(p0->num1 <= p1->num1)
{
if(head1==p1) head1=p0;
else p2->next=p0;
p0->next=p1;
}
else
{
p1->next=p0;
p0->next=NULL;
}
}
N1=N1+1;
}
void delc(int num1)//课程管理子函数(删除课程)
{
struct couse *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;
else p2->next=p1->next;
printf("已删除该编号课程!\n");
N1=N1-1;
}
else printf("无该编号的课程!\n");
end:;
}
void managementc()//课程管理主函数
{
struct couse * incouse;
int i,num1;
printf("\t\t\t课程管理\n");
printf("1.新增课程\n");
printf("2.删除课程\n");
printf("3.返回主菜单\n");
printf("请选择(1~3):\n");
scanf("%d",&i);
switch(i)
{
case(1):
{
incouse=(struct couse *)malloc(sizeof(struct couse));
printf("课程编号\t课程名称\t学分\t课程人数上限\n");
scanf("%d%s%d%d",&incouse->num1,incouse->name1,&incouse->score,&incouse->Melepeo);
incouse->nelepeo=0;
insertc(incouse);
break;
}
case(2):
{
printf("请输入要删除课程的编号:\n");
scanf("%d",&num1);
delc(num1);
break;
}
case(3):break;
}
}
void keyboards()//录入学生信息子函数(从键盘录入)
{
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->nelenum[i]=0;
head2=NULL;
while(p1->num2!=0)
{
N2=N2+1;
if(N2==1)head2=p1;
else p2->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->nelenum[i]=0;
}
p2->next=NULL;
}
void files()//录入学生信息子函数(从文件录入)
{
int i=0;
FILE * fp;
char filepath[20];
struct student *p1,*p2;
N2=0;
printf("输入要读入的文件路径:");
getchar();
gets(filepath);
if((fp=fopen(filepath,"r"))==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)head2=p1;
else p2->next=p1;
p2=p1;
p1=(struct student * )malloc(sizeof(struct student));
fread(p1,sizeof(struct student),1,fp);
}
p2->next=NULL;
}
void inputs()//录入学生信息主函数
{
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):keyboards();break;
case(2):files();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;
}
else
{
while((p0->num2 > p1->num2) && (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;
}
else
{
p1->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->num2 && p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(num2==p1->num2)
{
if(p1==head2) head2=p1->next;
else p2->next=p1->next;
printf("已删除该学生信息!\n");
N2=N2-1;
}
else printf("无该学号的学生!\n");
end:;
}
void managements()//学生信息管理主函数
{
struct student * incouse;
int i,num2;
printf("\t\t\t学生信息管理\n");
printf("1.新增学生信息\n");
printf("2.删除学生信息\n");
printf("3.返回主菜单\n");
printf("请选择(1~3):\n");
scanf("%d",&i);
switch(i)
{
case(1):
{
incouse=(struct student *)malloc(sizeof(struct student));
incouse->nelen=0;
incouse->nelenum[0]=0;
printf("学生学号\t学生姓名\n");
scanf("%d%s",&incouse->num2,incouse->name2);
inserts(incouse);
break;
}
case(2):
{
printf("请输入要删除学生的学号:\n");
scanf("%d",&num2);
dels(num2);
break;
}
case(3):break;
}
}
void elect(struct student * s)//选课
{
struct couse * p;
int num1,i;
printf("请输
蚊子的
- 粉丝: 9
- 资源: 25
最新资源
- UnboundLocalError.md
- PluginError解决办法.md
- SocketTimeoutException(解决方案).md
- NSDataCompressionError如何解决.md
- BindException(解决方案).md
- StoreError解决办法.md
- NSDataDecompressionError如何解决.md
- ProtocolException(解决方案).md
- RouterError解决办法.md
- UnicodeError.md
- NSAttributedStringError如何解决.md
- NoClassDefFoundError(解决方案).md
- UnicodeEncodeError.md
- NavigationGuardError解决办法.md
- NSStreamError如何解决.md
- UnicodeDecodeError.md
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈