学生选修课程系统设计.docx
- 文档编号:23496484
- 上传时间:2023-05-17
- 格式:DOCX
- 页数:15
- 大小:150.44KB
学生选修课程系统设计.docx
《学生选修课程系统设计.docx》由会员分享,可在线阅读,更多相关《学生选修课程系统设计.docx(15页珍藏版)》请在冰豆网上搜索。
学生选修课程系统设计
学生选修课程系统设计
一、课题题目学生选修课程系统设计假定有几门课程,每门课程有课程编号、课程名称、课程性质、总学时、授课学时、实验或上机学时、学分、开科学期等信息,学生可按要求(如总学分不得少于60)自选课。
试设计一选修课程系统,使之能提供以下功能:
系统以菜单方式工作。
课程信息录入功能(课程信息用文件保存)——输入。
课程信息浏览功能——输出。
查询功能(至少一种查询方式)——算法。
按学分查询。
按课程性质查询。
学生选修课程(可选项)。
二、设计目的:
通过本课程的实验设计,以便我们能够掌握C语言的设计思想,为以后的设计和开发积累经验。
三、设计要求:
实现以下功能:
系统以菜单方式工作。
课程信息录入功能(课程信息用文件保存)——输入。
课程信息浏览功能——输出。
查询功能(至少一种查询方式)——算法。
按学分查询。
按课程性质查询。
学生选修课程(可选项)。
四、总体设计:
其框架图如下:
五、程序代码
#include
#include
#include
typedefstructsubjects
{
intnum;
charname[20];
charkind[10];
intstime;
intttime;
intetime;
intscore;
intterm;
structsubjects*next;
}SUB;
SUB*create_form()
{
SUB*head,*tail,*p;
intnum,stime,ttime;
intetime,score,term;
charname[20],kind[10];
intsize=sizeof(SUB);
head=tail=NULL;
printf("输入选修课程信息:
\n");
scanf("%d%s%s%d%d%d%d%d",&num,&name,&kind,&stime,&ttime,&etime,&score,&term);
while(num!
=0){
p=(SUB*)malloc(size);
p->num=num;
strcpy(p->name,name);
strcpy(p->kind,kind);
p->stime=stime;
p->ttime=ttime;
p->etime=etime;
p->score=score;
p->term=term;
if(head==NULL)
head=p;
else
tail->next=p;
tail=p;
scanf("%d%s%s%d%d%d%d%d",&num,&name,&kind,&stime,&ttime,&etime,&score,&term);
}
tail->next=NULL;
returnhead;
}
voidsavefile(SUB*head)
{
SUB*p;
FILE*fp;
fp=fopen("subjects.txt","w");
fprintf(fp,"课程编号课程名称课程性质总学时授课学时实验或上机学时学分开课学期\n");
for(p=head;p;p=p->next)
fprintf(fp,"%5d%12s%9s%9d%9d%11d%11d%7d\n",p->num,p->name,p->kind,p->stime,p->ttime,p->etime,p->score,p->term);
fclose(fp);
}
voidsavefileadd(SUB*head)
{
SUB*p;
FILE*fp;
fp=fopen("subjectsadd.txt","w");
fprintf(fp,"课程编号课程名称课程性质总学时授课学时实验或上机学时学分开课学期\n");
for(p=head;p;p=p->next)
fprintf(fp,"%5d%12s%9s%9d%9d%11d%11d%7d\n",p->num,p->name,p->kind,p->stime,p->ttime,p->etime,p->score,p->term);
fclose(fp);
}
voidsavefiledel(SUB*head)
{
SUB*p;
FILE*fp;
fp=fopen("subjectsdel.txt","w");
fprintf(fp,"课程编号课程名称课程性质总学时授课学时实验或上机学时学分开课学期\n");
for(p=head;p;p=p->next)
fprintf(fp,"%5d%12s%9s%9d%9d%11d%11d%7d\n",p->num,p->name,p->kind,p->stime,p->ttime,p->etime,p->score,p->term);
fclose(fp);
}
voidprin(SUB*head)
{
SUB*ptr;
if(head==NULL){
printf("没有此门课程记录!
\n");
return;
}
printf("课程编号课程名称课程性质总学时授课学时实践或上机学时学分开课学期\n");
for(ptr=head;ptr;ptr=ptr->next)
printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,ptr->ttime,ptr->etime,ptr->score,ptr->term);
}
voidsearch(SUB*head)
{
inta,num;
intt=1;
chartype[10];
charch='a',ch1;
SUB*ptr;
while(ch!
=''){
printf("若要按课程性质查找请输入1,若要按学分查找请输入2:
\n");
scanf("%d",&a);
switch(a){
case1:
printf("请输入要查找的课程的性质:
\n");
scanf("%s",type);
printf("课程编号课程名称课程性质总学时授课学时实践或上机学时学分开课学期\n");
for(ptr=head;ptr;ptr=ptr->next)
if(strcmp(type,ptr->kind)==0){
printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,ptr->ttime,ptr->etime,ptr->score,ptr->term);
t=0;
}
if(t)printf("未找到!
\n");
t=1;
break;
case2:
printf("输入要查找的课程的学分\n");
scanf("%d",&num);
printf("课程编号课程名称课程性质总学时授课学时实践或上机学时学分开课学期\n");
for(ptr=head;ptr;ptr=ptr->next)
if(ptr->score==num){
printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,ptr->ttime,ptr->etime,ptr->score,ptr->term);
t=0;
}
if(t)printf("未找到!
\n");
t=1;
}
printf("继续查找请按回车键,结束请按空格键:
\n");
ch1=getchar();//将回车键赋给CH1,否则CASE里面最后输入的回车键会赋给CH,因此用CH1填补。
ch=getchar();
}
}
SUB*insert(SUB*head)
{
SUB*ptr,*ptr2,*subj;
intsize=sizeof(SUB);
charch='a',ch1;
while(ch!
=''){
subj=(SUB*)malloc(size);
ptr=subj;
printf("输入要插入的课程信息:
\n");
scanf("%d%s%s%d%d%d%d%d",&subj->num,subj->name,subj->kind,&subj->stime,&subj->ttime,&subj->etime,&subj->score,&subj->term);
if(head==NULL){
head=ptr;
head->next=NULL;
}
else{
for(ptr2=head;ptr2;ptr2=ptr2->next)
if(ptr2->next==NULL){
ptr2->next=subj;
subj->next=NULL;
break;
}
}
printf("继续插入请按回车,结束请按空格:
\n");
ch1=getchar();//将回车键赋给CH1,否则subj->term输完后输入的回车键会赋给CH,因此用CH1填补。
ch=getchar();
}
returnhead;
}
SUB*del(SUB*head)
{
SUB*p1,*p2;
charch='a',ch1;
intnum;
while(ch!
=''){
printf("输入想要删除的课程编号:
\n");
scanf("%d",&num);
if(head->num==num){
p2=head;
head=head->next;
free(p2);
}
if(head==NULL)
returnNULL;
p1=head;
p2=head->next;
while(p2){
if(p2->num==num){
p1->next=p2->next;
free(p2);
}
elsep1=p2;
p2=p1->next;
}
printf("继续删除请按回车,结束请按空格:
\n");
ch1=getchar();//将回车键赋给CH1,否则num输完后再输入的回车键会赋给CH,因此用CH1填补。
ch=getchar();
}
returnhead;
}
voidchoose(SUB*head)
{
SUB*p,*q;
inta[5];
intnum,total=0,i=0,j;
printf("输入要选修的课程的编号,编号之间以空格分开,输完后以0结束\n");
scanf("%d",&num);
while(num!
=0){
for(p=head;p;p=p->next)
if(p->num==num){
total=total+p->score;
a[i]=num;
i++;
}
scanf("%d",&num);
}
if(total<60)printf("选修总学分未达到60,选修失败!
\n");
else{
printf("选修成功!
\n");
printf("您选修的课程为:
\n");
for(j=0;j
for(q=head;q;q=q->next)
if(q->num==a[j])
printf("%s",q->name);
printf("\n");
printf("***********************************\n");
printf("学号姓名\n");
printf("***********************************\n");
}
}
voidmain()
{
SUB*head=create_form();
savefile(head);
prin(head);
search(head);
head=insert(head);//注意此处的必要性,函数insert的的返回值重新赋给head!
savefileadd(head);
printf("修改后的信息为:
\n");
prin(head);
head=del(head);//注意此处的必要性,函数del的的返回值重新赋给head!
savefiledel(head);
printf("修改后的课程信息为:
\n");
prin(head);
choose(head);
}
六、程序调试
1.输入选修课程信息(按回车结束)。
2.输出选修课程信息。
3.按学分查询选修课程信息。
4.按课程性质查询选修课程信息。
5.插入一门选修课程信息。
6.输出修改后的选修课程信息。
7.输入要删除的课程编号。
9.输出最终的选修课程信息
8.输出选择的课程信息。
七、心得
刚开始,可以说是没有头绪,于是就去图书馆找资料,找到了一些关于整体设计方面的,可是这点小进展远远不够,这只是一个小小的开始。
下一步是上网查,找到了些与我们题目相似的,那时我们每个人都很高兴,可是那还不是我们要的,于是又上网查到了些有关的函数等等,终于在我们大家的努力下,完成了这个程序。
虽然对着电脑做程序,有点累有点热,可是当看到劳动成果时,真是别有一番滋味在心头啊!
世上无难事,只怕有心人,的确如此。
做完这个程序最大的收获就是感受到了集体的力量,当然个人的智慧也是很重要的哦!
做完这个课程设计,我们的自信一下子提高了,我们也会写程序了;尽管对于有些人这种程序会很简单,可对我们C语言初学者来说,已经很不容易了。
这次体验为以后的学习计算机的我们增强了信心。
享受劳动成果的滋味实在很美妙啊!
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 学生 选修 课程 系统 设计