C语言学生选课系统(代码)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include
#include
#include
int N1,N2;
struct student
{
int num2;
char name2[20];
int nelenum[50]; //所选课程编号
int nelen; //所选课程学分和
struct student * next;
};
struct course
{
int num1; //课程编号
char name1[20];
char major[20];
char type[20];
int credit;
int period;
char teacher[20];
int people; //选此门课程的人数struct course *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->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,&p1->cr edit,&p1->period,p1->teacher);
p1->people=0;
}
p2->next=NULL;
}
void zhang1() //从文件录入课程信息
{
FILE * fp;
char filepath[20];
struct course *p1,*p2;
N1=0;
printf("请输入您要读取的路径:");
getchar();
gets(filepath);
if((fp=fopen(filepath,"r"))==NULL)
{
printf("找不到%s 文件!\n",filepath);
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;
else
p2->next=p1;
p2=p1;
p1=(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("\t\t\t录入课程信息\n");
printf("\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;
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;