选课小系统 科大.docx
《选课小系统 科大.docx》由会员分享,可在线阅读,更多相关《选课小系统 科大.docx(31页珍藏版)》请在冰点文库上搜索。
选课小系统科大
成绩
C++程序设计
综合性实验
学生选课小系统
学号
201212010119
姓名
杨静娜
班级
数学121
学生选课小系统
综合性实验任务书
实验项目名称:
学生选课小系统
课程名称:
C++程序设计
面向专业:
信息与计算机相关专业
计划学时:
4学时
实验类型:
√综合设计
实验目的:
综合练习课程的所有知识点,熟练面向对象程序设计的方法和流程,提高分析和解决问题的能力,培养动手能力。
实验要求:
包括开发环境要求、技术文档要求两部分。
开发环境要求:
软件环境:
windowsXP/windows7
硬件环境:
计算机(Pen4CPU,512MRAM,60G以上硬盘)
技术文档要求:
按照实验报告编写要求进行。
要求相关图表绘制规范,软、硬件功能描述清晰,实验总结真实深刻。
实验内容:
建立课程类和学生类。
学生基本信息包括学号和姓名两项。
要求实现:
每个学生最多可选5门课,最少要选2门课。
根据学生实际选的课,确定学生姓名。
能查询学生选的所有课程的成绩,能得出学生所选课程的平均成绩。
可以为某个学生增加一门课或者去掉一门课,并在课程里同时增加或者去掉该学生的姓名。
每门课最多允许40名学生选,能查询每门课已选的学生人数及学生姓名名单。
每门课设置学分,每门课有所有学生成绩,可以为课程设置学分数,每门课可以查到选该门课的某个学生的成绩,也可以得到选该门课的所有学生的平均成绩。
实验仪器设备:
每个学生一台计算机,配置相关软件。
实验报告版式要求
A4纸张打印;上下页边距各2.5cm,左右页边距各3.0cm,页眉1.5cm页脚1.75cm;页码位于页脚居中打印;奇数页页眉“C++程序设计综合性实验”,偶数页页眉“学生选课小系统”,页眉宋体小5号,一级标题:
黑体三号粗体字;二级标题:
黑体4号;三级标题黑体小4号,正文,宋体5号。
学生选课小系统综合性实验报告
实验名称:
学生选课小系统
专业班级数学121学号201212010119姓名杨静娜报告日期
实验目的:
综合练习课程的所有知识点,熟练面向对象程序设计的方法和流程,提高分析和解决问题的能力,培养动手能力。
实验要求:
软件环境:
VisualC++6.0
硬件环境:
计算机(Pen4CPU,512MRAM,60G以上硬盘)
实验内容:
建立课程类和学生类。
学生基本信息包括学号和姓名两项。
要求实现:
每个学生最多可选5门课,最少要选2门课。
根据学生实际选的课,确定学生姓名。
能查询学生选的所有课程的成绩,能得出学生所选课程的平均成绩。
可以为某个学生增加一门课或者去掉一门课,并在课程里同时增加或者去掉该学生的姓名。
每门课最多允许40名学生选,能查询每门课已选的学生人数及学生姓名名单。
每门课设置学分,每门课有所有学生成绩,可以为课程设置学分数,每门课可以查到选该门课的某个学生的成绩,也可以得到选该门课的所有学生的平均成绩。
实验结果及分析:
实验体会与总结:
参考文献
实验结果及分析:
运行:
1、进入
2、录入课程信息
3、课程管理
4、录入学生信息
5、学生信息管理
6、系统信息查看及存储
程序
#include
#include
intN1,N2,kk1,kk2,kk3;
structcouse*head1;
structstudent*head2;
structcouse
{
intnum1;
charname1[20];
intscore;
intnelepeo;//课程已选人数
intMelepeo;//课程人数上限
structcouse*next;
}
structstudent//学生信息结构体
{
intnum2;
charname2[20];
intnelenum[50];//已选课程编号
intnelen;//已选课程数量
structstudent*next;
}
voidMs()
{
for(kk1=0;kk1<1100;kk1++)
for(kk2=0;kk2<1200;kk2++)
for(kk3=0;kk3<1200;kk3++);
}
voidkeyboardc()//录入课程子函数(从键盘录入)
{
structcouse*p1,*p2;
N1=0;
p1=p2=(structcouse*)malloc(sizeof(structcouse));
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;
elsep2->next=p1;
p2=p1;
p1=(structcouse*)malloc(sizeof(structcouse));
scanf("%d%s%d%d",&p1->num1,p1->name1,&p1->score,&p1->Melepeo);
p1->nelepeo=0;
}
p2->next=NULL;
}
voidfilec()//录入键盘子函数(从文件录入)
{
FILE*fp;
charfilepath[20];
structcouse*p1,*p2;
N1=0;
printf("输入要读入的文件路径:
");
getchar();
gets(filepath);
if((fp=fopen(filepath,"r"))==NULL)
{
printf("找不到%s文件!
\n",filepath);
exit(0);
}
p1=p2=(structcouse*)malloc(sizeof(structcouse));
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;
elsep2->next=p1;
p2=p1;
p1=(structcouse*)malloc(sizeof(structcouse));
fscanf(fp,"%d%s%d%d%d",&p1->num1,p1->name1,&p1->score,&p1->nelepeo,&p1->Melepeo);
}
p2->next=NULL;
}
voidinputc()//录入课程主函数
{
inti;
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;
}
}
voidinsertc(structcouse*incouse)//课程管理子函数(增加课程)
{
structcouse*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;
elsep2->next=p0;
p0->next=p1;
}
else
{
p1->next=p0;
p0->next=NULL;
}
}
N1=N1+1;
}
voiddelc(intnum1)//课程管理子函数(删除课程)
{
structcouse*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;
elsep2->next=p1->next;
printf("已删除该编号课程!
\n");
N1=N1-1;
}
elseprintf("无该编号的课程!
\n");
end:
;
}
voidmanagementc()//课程管理主函数
{
structcouse*incouse;
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)
{
case
(1):
{
incouse=(structcouse*)malloc(sizeof(structcouse));
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;
}
}
voidkeyboards()//录入学生信息子函数(从键盘录入)
{
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;
elsep2->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;
}
voidfiles()//录入学生信息子函数(从文件录入)
{
inti=0;
FILE*fp;
charfilepath[20];
structstudent*p1,*p2;
N2=0;
printf("输入要读入的文件路径:
");
getchar();
gets(filepath);
if((fp=fopen(filepath,"r"))==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;
elsep2->next=p1;
p2=p1;
p1=(structstudent*)malloc(sizeof(structstudent));
fread(p1,sizeof(structstudent),1,fp);
}
p2->next=NULL;
}
voidinputs()//录入学生信息主函数
{
inti;
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;
}
}
voidinserts(structstudent*incouse)//学生信息管理子函数(填加学生信息)
{
structstudent*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;
elsep2->next=p0;
p0->next=p1;
}
else
{
p1->next=p0;
p0->next=NULL;
}
}
N2=N2+1;
}
voiddels(intnum2)//学生信息管理子函数(删除学生信息)
{
structstudent*p1,*p2;
if(head2==NULL)
{
printf("\n没有该学生信息,无法删除!
\n");
gotoend;
}
p1=head2;
while(num2!
=p1->num2&&p1->next!
=NULL)
{
p2=p1;
p1=p1->next;
}
if(num2==p1->num2)
{
if(p1==head2)head2=p1->next;
elsep2->next=p1->next;
printf("已删除该学生信息!
\n");
N2=N2-1;
}
elseprintf("无该学号的学生!
\n");
end:
;
}
voidmanagements()//学生信息管理主函数
{
structstudent*incouse;
inti,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=(structstudent*)malloc(sizeof(structstudent));
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;
}
}
voidelect(structstudent*s)//选课
{
structcouse*p;
intnum1,i;
printf("请输入要选课的编号:
\n");
scanf("%d",&num1);
for(i=0;s->nelenum[i]!
=0;i++);
s->nelenum[i]=num1;
(s->nelen)++;
p=head1;
while(p->num1!
=num1)p=p->next;
(p->nelepeo)++;
}
voidcheak()//学生选课子函数(查询可选课程)
{
chare;
structcouse*c;
structstudent*s;
intnum2,i,j=0,t=0;
printf("请输入你的学号:
");
scanf("%d",&num2);
s=head2;
while(s->num2!
=num2&&s->next!
=NULL)s=s->next;
if(s->num2!
=num2)
{
printf("不存在你的信息,请进入主菜单录入你的信息!
\n");
gotoend;
}
c=head1;
printf("你的可选课程编号:
\n");
while(c!
=NULL)
{
for(t=0,i=0;s->nelenum[i]!
=0;i++)
{
if(c->num1==s->nelenum[i])t=1;
}
if(t==0&&(c->nelepeo!
=c->Melepeo))
{
printf("%d\n",c->num1);
j++;
}
c=c->next;
}
if(j==0)
{
printf("你已选完所有课程,无法再多选!
\n");
gotoend;
}
printf("选课(y/n)?
:
\n");
getchar();
e=getchar();
i=0;
while(e=='y')
{
elect(s);
printf("继续选课(y/n)?
:
\n");
getchar();
e=getchar();
}
end:
;
}
voidback(structstudent*p)//退课
{
structcouse*p1;
intnum1,i,j;
printf("请输入你要退掉的课程编号:
\n");
scanf("%d",&num1);
p1=head1;
while(p1->num1!
=num1)p1=p1->next;
for(i=0;p->nelenum[i]!
=num1;i++);
for(j=i;p->nelenum[j]!
=0;j++)p->nelenum[j]=p->nelenum[j+1];
p->nelenum[--j]=0;
(p1->nelepeo)--;
printf("退课成功!
\n");
}
voidhcheak()//学生选课子函数(查询已选课程)
{
charc;
structcouse*p0;
structstudent*p;
intnum2,i,f=0;
printf("请输入学号:
\n");
scanf("%d",&num2);
p=head2;
while(p->num2!
=num2&&p!
=NULL)p=p->next;
if(p==NULL)
{
printf("不存在你的信息,请回主菜单录入信息:
\n");
gotoend;
}
printf("已选课程编号:
\n");
if(p->nelenum[0]==0)
{
printf("你还没选课!
\n");
gotoend;
}
for(i=0;p->nelenum[i]!
=0;i++)
{
printf("%d\n",p->nelenum[i]);
p0=head1;
while(p0->num1!
=p->nelenum[i])p0=p0->next;
f=f+p0->score;
}
printf("总学分:
%d\n",f);
printf("是否进行退课(y/n)?
");
getchar();
c=getchar();
while(c=='y')
{