c语言程序设计之学生选修课系统设计代码.docx

上传人:b****1 文档编号:10740635 上传时间:2023-05-27 格式:DOCX 页数:16 大小:17.51KB
下载 相关 举报
c语言程序设计之学生选修课系统设计代码.docx_第1页
第1页 / 共16页
c语言程序设计之学生选修课系统设计代码.docx_第2页
第2页 / 共16页
c语言程序设计之学生选修课系统设计代码.docx_第3页
第3页 / 共16页
c语言程序设计之学生选修课系统设计代码.docx_第4页
第4页 / 共16页
c语言程序设计之学生选修课系统设计代码.docx_第5页
第5页 / 共16页
c语言程序设计之学生选修课系统设计代码.docx_第6页
第6页 / 共16页
c语言程序设计之学生选修课系统设计代码.docx_第7页
第7页 / 共16页
c语言程序设计之学生选修课系统设计代码.docx_第8页
第8页 / 共16页
c语言程序设计之学生选修课系统设计代码.docx_第9页
第9页 / 共16页
c语言程序设计之学生选修课系统设计代码.docx_第10页
第10页 / 共16页
c语言程序设计之学生选修课系统设计代码.docx_第11页
第11页 / 共16页
c语言程序设计之学生选修课系统设计代码.docx_第12页
第12页 / 共16页
c语言程序设计之学生选修课系统设计代码.docx_第13页
第13页 / 共16页
c语言程序设计之学生选修课系统设计代码.docx_第14页
第14页 / 共16页
c语言程序设计之学生选修课系统设计代码.docx_第15页
第15页 / 共16页
c语言程序设计之学生选修课系统设计代码.docx_第16页
第16页 / 共16页
亲,该文档总共16页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

c语言程序设计之学生选修课系统设计代码.docx

《c语言程序设计之学生选修课系统设计代码.docx》由会员分享,可在线阅读,更多相关《c语言程序设计之学生选修课系统设计代码.docx(16页珍藏版)》请在冰点文库上搜索。

c语言程序设计之学生选修课系统设计代码.docx

c语言程序设计之学生选修课系统设计代码

#include

#include

#include

#include

#include

intn=0;//n为结点个数

structkecheng//声明结构体

{

intbianhao;

charname[10];

charxingzhi[10];

intzongxueshi;

intshoukexueshi;

intshangjixueshi;

floatxuefen;

intkaikexueqi;

structkecheng*next;

};

structkecheng*head;

structkecheng*creat()//创建链表.此函数带回一个指向链表头的指针

{

voidsave(structkecheng*head);

printf("课程编号课程名称课程性质总学时授课学时实践或上机学时学分开课学期\n");

structkecheng*head,*p1,*p2;

p1=p2=(structkecheng*)malloc(sizeof(structkecheng));//开辟一个新单元

scanf("%d",&p1->bianhao);

head=NULL;

while(p1->bianhao!

=0)

{

scanf("%s%s%d%d%d%f%d",p1->name,p1->xingzhi,&p1->zongxueshi,&p1->shoukexueshi,&p1->shangjixueshi,&p1->xuefen,&p1->kaikexueqi);

n++;

if(n==1)

head=p1;

else

p2->next=p1;

p2=p1;

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

scanf("%d",&p1->bianhao);

}

p2->next=NULL;

save(head);

return(head);

}

voidsave(structkecheng*head)//保存到文件中

{

structkecheng*p;

FILE*fp;

fp=fopen("所有课程信息.txt","w");//把输入的课程信息在kecheng.txt中保存

p=head;

while(p!

=NULL)

{

fprintf(fp,"%d\t%s\t%s\t%d\t%d\t%d\t%.1f\t%d\n",p->bianhao,p->name,p->xingzhi,p->zongxueshi,p->shoukexueshi,p->shangjixueshi,p->xuefen,p->kaikexueqi);

p=p->next;

}

fclose(fp);

}

voidchakan(structkecheng*head)//查看所有课程信息,即可以选的课程

{

structkecheng*p;

p=head;

printf("课程编号课程名称课程性质总学时授课学时实践或上机学时学分开课学期\n");

while(p!

=NULL)

{

printf("%d\t%s\t%s\t%d\t%d\t%d\t%.1f\t%d\n",p->bianhao,p->name,p->xingzhi,p->zongxueshi,p->shoukexueshi,p->shangjixueshi,p->xuefen,p->kaikexueqi);

p=p->next;

}

}

voidsearch(structkecheng*head)//按编号或性质查询

{

inta,bianhao;//a为对菜单进行选择的变量

intflag=1;//flag为判断是否找到该课程

charxingzhi[10];

structkecheng*p;

printf("若要按课程性质查找请输入1\n");

printf("若要按课程编号查找请输入2\n");

printf("退出查询请按0\n");

scanf("%d",&a);

while(a!

=0)

{

switch(a)

{

case1:

printf("请输入要查找的课程的性质:

\n");//以课程性质选课

scanf("%s",xingzhi);

printf("课程编号课程名称课程性质总学时授课学时实践或上机学时学分开课学期\n");

p=head;

while(p!

=NULL)

{

if(strcmp(xingzhi,p->xingzhi)==0)

{

printf("%d\t%s\t%s\t%d\t%d\t%d\t%.1f\t%d\n",p->bianhao,p->name,p->xingzhi,p->zongxueshi,p->shoukexueshi,p->shangjixueshi,p->xuefen,p->kaikexueqi);

flag=0;

}

p=p->next;

}

if(flag==1)

printf("对不起,未找到,请重新输入或退出!

\n");

flag=1;

break;

case2:

printf("输入要查找的课程的编号\n");//以课程编号选课

scanf("%d",&bianhao);

printf("课程编号课程名称课程性质总学时授课学时实践或上机学时学分开课学期\n");

p=head;

while(p!

=NULL)

{

if(p->bianhao==bianhao)

{

printf("%d\t%s\t%s\t%d\t%d\t%d\t%.1f\t%d\n",p->bianhao,p->name,p->xingzhi,p->zongxueshi,p->shoukexueshi,p->shangjixueshi,p->xuefen,p->kaikexueqi);

flag=0;

}

p=p->next;

}

if(flag==1)

printf("对不起,未找到,请重新输入或退出!

\n");

flag=1;

break;

}

printf("若要按课程性质查找请输入1\n");

printf("若要按课程编号查找请输入2\n");

printf("退出查询请按0\n");

scanf("%d",&a);

}

}

voidxuanke(structkecheng*head)//学生按编号选课

{

FILE*fp;

fp=fopen("学生已选课.txt","w");

intbianhao,i=0,j,a[20];//数组a中存放已选好的课程

structkecheng*p;

floats=0;//s为统计所选课程的学分

printf("请输入你想选的课程编号,以0结束:

\n");

scanf("%d",&bianhao);

while(bianhao!

=0)

{

for(j=0;j

if(bianhao==a[j])

{

printf("你已选了该课程,请重新输入或以0退出:

\n");

scanf("%d",&bianhao);

continue;

}

p=head;

while(p!

=NULL)//从链表表头开始寻找该课程

{

if(bianhao!

=p->bianhao)

p=p->next;

else

break;

}

if(p==NULL)

printf("无此课程,请重新输入\n");

else

{

s=s+p->xuefen;//若选课成功,就把该课程的学分累加

printf("课程编号课程名称课程性质总学时授课学时实践或上机学时学分开课学期\n");

printf("%d\t%s\t%s\t%d\t%d\t%d\t%.1f\t%d\n",p->bianhao,p->name,p->xingzhi,p->zongxueshi,p->shoukexueshi,p->shangjixueshi,p->xuefen,p->kaikexueqi);

a[i]=bianhao;

fprintf(fp,"%d\t%s\t%s\t%d\t%d\t%d\t%.1f\t%d\n",p->bianhao,p->name,p->xingzhi,p->zongxueshi,p->shoukexueshi,p->shangjixueshi,p->xuefen,p->kaikexueqi);

i++;

}

scanf("%d",&bianhao);

}fclose(fp);

if(s<60)

printf("选课失败\n");

else

printf("选课成功\n");

}

structkecheng*del(structkecheng*head)//删除一门课程

{

intm;//m为想删除课程的编号

structkecheng*p1,*p2;

p1=head;

printf("请输入你要删除课程的编号,以0结束:

\n");

scanf("%d",&m);

while(m!

=0)

{

while(m!

=p1->bianhao&&p1->next!

=NULL)//p1指向的不是所要找的课程编号

{

p2=p1;

p1=p1->next;//p1后移一个结点

}

if(m==p1->bianhao)

{

if(p1==head)//若p1指向的是首结点,把第二个结点地址赋给head

head=p1->next;//否则将下一结点地址赋给前一结点地址

elsep2->next=p1->next;

n=n-1;

}

else

printf("找不到你要删除的课程!

\n");

scanf("%d",&m);

}

save(head);

return(head);

}

structkecheng*insert(structkecheng*head)//增加一门课程的函数

{

structkecheng*p0,*p1,*p2;//insert_kc为增加课程的变量

p1=head;p0=(structkecheng*)malloc(sizeof(structkecheng));//p1指向第一个结点,p0指向要插入的结点

printf("请输入你要增加的课程:

\n");

printf("课程编号课程名称课程性质总学时授课学时实践或上机学时学分开课学期\n");

scanf("%d%s%s%d%d%d%f%d",&p0->bianhao,p0->name,p0->xingzhi,&p0->zongxueshi,&p0->shoukexueshi,&p0->shangjixueshi,&p0->xuefen,&p0->kaikexueqi);

while((p0->bianhao>p1->bianhao)&&(p1->next!

=NULL))

{

p2=p1;//使p2指向刚才p1指向的结点

p1=p1->next;//p1后移一个结点

}

if(p0->bianhao<=p1->bianhao)

{

if(head==p1)

head=p0;//将增加课程的地址插到原来第一个结点之前

else

p2->next=p0;//插到p2指向的结点之后

p0->next=p1;

}

else

{

p1->next=p0;p0->next=NULL;//插到最后的结点之后

}

n=n+1;//结点数加1

save(head);

return(head);

}

structkecheng*write()

{

FILE*fp;

structkecheng*head,*p1,*p2;

//fp=fopen("所有课程信息.txt","r");

if((fp=fopen("所有课程信息.txt","r"))==NULL)

{printf("nodatapleaseinputsourcedata\n");

head=creat();

//head=creat();

//returnNULL;

}//把文件中的信息写入一个链表

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

fscanf(fp,"%d",&p1->bianhao);

head=NULL;

while(!

feof(fp))

{

fscanf(fp,"%s%s%d%d%d%f%d",p1->name,p1->xingzhi,&p1->zongxueshi,&p1->shoukexueshi,&p1->shangjixueshi,&p1->xuefen,&p1->kaikexueqi);

n++;

if(n==1)

head=p1;

else

p2->next=p1;

p2=p1;

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

fscanf(fp,"%d",&p1->bianhao);

}

p2->next=NULL;

returnhead;

}

voidyixuan()

{

FILE*fp;structkechenga[20];

inti=0,j;

fp=fopen("学生已选课.txt","r");

while(!

feof(fp))

{

fscanf(fp,"%d%s%s%d%d%d%f%d\n",&a[i].bianhao,a[i].name,a[i].xingzhi,&a[i].zongxueshi,&a[i].shoukexueshi,&a[i].shangjixueshi,&a[i].xuefen,&a[i].kaikexueqi);

i++;

}

fclose(fp);

printf("课程编号课程名称课程性质总学时授课学时实践或上机学时学分开课学期\n");

for(j=0;j

printf("%d\t%s\t%s\t%d\t%d\t%d\t%.1f\t%d\n",a[j].bianhao,a[j].name,a[j].xingzhi,a[j].zongxueshi,a[j].shoukexueshi,a[j].shangjixueshi,a[j].xuefen,a[j].kaikexueqi);

}

voidwelcome()

{

charc=2;//ASCII码对应的图形,一个笑脸

printf("\t\t\t***********************************\n");//主菜单

printf("\t\t\t*欢迎使用选课系统*\n");

printf("\t\t\t***********************************\n");

printf("%c管理员登入请按1\n",c);//不同的对象登入后下有不同的子菜单

printf("%c学生选课登入请按2\n",c);

}

voidteacher_welcome()//欢迎管理员的菜单

{

charc=2,str[8];//ASCII码对应的图形,一个笑脸,str为存放密码的数组

inti,m=0;//m为统计输入密码的次数

printf("请输入8位密码\n");

getchar();

gets(str);

for(i=0;i<3;i++)

{

if(strcmp(str,"20080806")==0)//密码正确,进入系统

{

printf("%c要输入课程信息请按1\n",c);

printf("%c要查看所有的课程信息请按2\n",c);

printf("%c要删除一门课程请按3\n",c);

printf("%c要增加一门课程请按4\n",c);

printf("%c要退出系统请按0\n",c);

break;

}

else

{

m++;

printf("密码错误,请重新输入:

\n");

gets(str);

}

}

if(m>=3)//密码错误超过三次退出系统

{

printf("对不起,密码错误超过三次!

\n");

exit(0);

}

}

voidstudent_welcome()//欢迎学生的菜单

{

charc=2;

printf("%c要查看所有的课程信息请按1\n",c);

printf("%c要查询你想选的课程请按2\n",c);

printf("%c要选修课程请按3\n",c);

printf("%c要查看已选课程请按4\n",c);

printf("%c要退出系统请按0\n",c);

}

voidmain()

{

intm;charc=2;

head=write();

welcome();

scanf("%d",&m);

if(m==1)//管理员登入后的菜单

{

teacher_welcome();

scanf("%d",&m);

while(m!

=0)

{

switch(m)

{

case1:

head=creat();break;//调用输入函数

case2:

chakan(head);break;//调用查看函数

case3:

head=del(head);break;//调用删除函数

case4:

head=insert(head);break;//调用增加函数

case0:

break;

}

printf("%c要输入课程信息请按1\n",c);

printf("%c要查看所有的课程信息请按2\n",c);

printf("%c要删除一门课程请按3\n",c);

printf("%c要增加一门课程请按4\n",c);

printf("%c要退出系统请按0\n",c);

scanf("%d",&m);

}

}

else//学生登入后的菜单

{

student_welcome();

scanf("%d",&m);

while(m!

=0)

{

switch(m)

{

case1:

chakan(head);break;//调用查看函数

case2:

search(head);break;//调用查询函数

case3:

xuanke(head);break;//调用选课函数

case4:

yixuan();break;//调用查看已选课程的函数

case0:

break;

}

student_welcome();

scanf("%d",&m);

}

}

}

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

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2