C语言学生选课系统代码.doc

上传人:b****1 文档编号:230173 上传时间:2022-10-07 格式:DOC 页数:21 大小:44.50KB
下载 相关 举报
C语言学生选课系统代码.doc_第1页
第1页 / 共21页
C语言学生选课系统代码.doc_第2页
第2页 / 共21页
C语言学生选课系统代码.doc_第3页
第3页 / 共21页
C语言学生选课系统代码.doc_第4页
第4页 / 共21页
C语言学生选课系统代码.doc_第5页
第5页 / 共21页
点击查看更多>>
下载资源
资源描述

C语言学生选课系统代码.doc

《C语言学生选课系统代码.doc》由会员分享,可在线阅读,更多相关《C语言学生选课系统代码.doc(21页珍藏版)》请在冰豆网上搜索。

C语言学生选课系统代码.doc

#include

#include

#include

intN1,N2;

structstudent

{

intnum2;

charname2[20];

intnelenum[50];//所选课程编号

intnelen;//所选课程学分和

structstudent*next;

};

structcourse

{

intnum1;//课程编号

charname1[20];

charmajor[20];

chartype[20];

intcredit;

intperiod;

charteacher[20];

intpeople;//选此门课程的人数

structcourse*next;//结构体指针

};

structcourse*head1;

structstudent*head2;

voidzhang()//从键盘录入课程信息

{

structcourse*p1,*p2;

N1=0;

p1=p2=(structcourse*)malloc(sizeof(structcourse));

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->credit,&p1->period,p1->teacher);

p1->people=0;

head1=NULL;

while(p1->num1!

=0)

{

N1=N1+1;

if(N1==1)head1=p1;

elsep2->next=p1;

p2=p1;

p1=(structcourse*)malloc(sizeof(structcourse));

scanf("%d%s%s%s%d%d%s",&p1->num1,p1->name1,p1->major,p1->type,&p1->credit,&p1->period,p1->teacher);

p1->people=0;

}

p2->next=NULL;

}

voidzhang1()//从文件录入课程信息

{

FILE*fp;

charfilepath[20];

structcourse*p1,*p2;

N1=0;

printf("请输入您要读取的路径:

");

getchar();

gets(filepath);

if((fp=fopen(filepath,"r"))==NULL)

{

printf("找不到%s文件!

\n",filepath);

exit(0);

}

p1=p2=(structcourse*)malloc(sizeof(structcourse));

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=(structcourse*)malloc(sizeof(structcourse));

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;

}

voidload()//录入课程信息函数

{

inti;

printf("\t\t\t录入课程信息\n");

printf("\n1.从键盘录入");

printf("\n2.从文件录入");

printf("\n3.返回主菜单\n");

printf("请选择1-3:

");

scanf("%d",&i);

switch(i)

{

case1:

zhang();break;

case2:

zhang1();break;

case3:

break;

}

}

voidinsert(structcourse*incourse)//增加课程信息

{

structcourse*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;

}

else

{

p1->next=p0;

p0->next=NULL;

}

}

N1=N1+1;

}

voiddelc(intnum1)//删除课程信息

{

structcourse*p1,*p2;

if(head1==NULL)

{

printf("\n无法删除!

\n");

gotoend;

}

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:

;

}

voidmanagementc()//课程信息管理函数

{

structcourse*p1;

inti,num1;

printf("\t\t\t课程信息管理\n");

printf("1.添加课程\n");

printf("2.删除课程\n");

printf("3.返回\n");

printf("请输入1-3:

\n");

scanf("%d",&i);

switch(i)

{

case1:

{p1=(structcourse*)malloc(sizeof(structcourse));

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->credit,&p1->period,p1->teacher);

p1->people=0;

insert(p1);

}break;

case2:

printf("请输入您要删除的课程编号:

\n");

scanf("%d",&num1);

delc(num1);break;

case3:

break;

}

}

voidputin(void)//从键盘录入学生信息

{

inti;

structstudent*p1,*p2;

N2=0;

p1=p2=(structstudent*)malloc(sizeof(structstudent));

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=(structstudent*)malloc(sizeof(structstudent));

scanf("%d%s",&p1->num2,p1->name2);

p1->nelen=0;

for(i=0;i<20;i++)p1->nelenum[i]=0;

}

p2->next=NULL;}

voidputin2()//从文件录入学生信息

{

inti=0;

FILE*fp;

charfilepath[20];

structstudent*p1,*p2;

N2=0;

printf("请输入您要读取的路径:

");

getchar();

gets(filepath);

if((fp=fopen(filepath,"rt"))==NULL)

{

printf("找不到%s文件!

\n",filepath);

exit(0);

}

p1=p2=(structstudent*)malloc(sizeof(structstudent));

fread(p1,sizeof(structstudent),1,fp);

head2=NULL;

while(!

feof(fp))

{

i=0;

N2=N2+1;

if(N2==1)

head2=p1;

else

p2->next=p1;

p2=p1;

p1=(structstudent*)malloc(sizeof(structstudent));

fread(p1,sizeof(st

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 考试认证 > IT认证

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1