学生成绩管理.docx
《学生成绩管理.docx》由会员分享,可在线阅读,更多相关《学生成绩管理.docx(16页珍藏版)》请在冰豆网上搜索。
学生成绩管理
学生成绩管理
指导教师李琳晧实验时间:
2011年12月1日
学院生物信息学院专业生物技术实验室S302
班级0621001学号2010212471姓名李言
班级0621001学号2010212481姓名谢保朋
实验题目:
学生成绩管理(限最多2人完成)1.主要功能:
(1)能按学期、按班级完成对学生成绩的录入、修改
(2)能按班级统计学生的成绩,求学生的总分及平均分,并能根据学生的平均成绩进行排序(3)能查询学生成绩,不及格科目及学生名单(4)能按班级输出学生的成绩单(5)系统以菜单方式工作
实验目的:
1、熟悉结构体、链表的使用
2、熟悉指向函数的指针、以及嵌套调用
3、学会规范、美观化设计程序
实验要求:
1.系统以菜单方式工作
2.学生信息录入功能
3.输出所有学生信息
4.按班级输出学生信息
5.对学生信息进行修改、删除
6、添加学生信息
7、对学生成绩进行排名
8、查询不及格学生的名单和科目
9、更改DOS界面的前景和背景颜色
10、每次重新输入都进行一次刷屏
实验主要步骤:
1.定义结构体;
2.建立链表存储学生信息;
3.设计菜单,在主函数中实现各个功能函数;
4.调试程序,找出问题,并且优化程序。
代码如下:
#include
#include
#include
structstu
{
intclassnumber;
charname[20];
intscore[3];
intsum;
floataverage;
structstu*next;
};
typedefstructstuSTU;
STU*head=NULL;
charmenu();
voidApplynode();
voidAddnode();
voidTotal(STU*p);
voidFailpass();
voidstudentlist();
voidclasslist();
voidchange();
voiddelect();
voidSort();
voidSortScore(int(*compare)(inta,intb));
//函数功能:
输出系统的主菜单,选择相应的功能后链接到其他函数实现对应的功能
charmenu(void)
{
charch;
printf("\t\t************************************************\n");
printf("\t\tMENU:
\n");
printf("\t\t1.输入学生成绩\n");
printf("\t\t2.输出所有学生成绩单\n");
printf("\t\t3.按班级输出成绩单\n");
printf("\t\t4.不及格科目及学生名单\n");
printf("\t\t5.增加一个学生信息\n");
printf("\t\t6.删除一个学生信息\n");
printf("\t\t7.修改一个学生信息\n");
printf("\t\t8.按总分实现排名\n");
printf("\t\t9.退出\n");
printf("\t\t************************************************\n");
printf("\n\n\t\tPleaseenteryourchoice:
");
fflush(stdin);
ch=getchar();
getchar();
return(ch);
}
//创建链表,输入学生的成绩
voidApplynode()
{
charc='y';
while(c=='Y'||c=='y')
{
Addnode();//为新的数据申请一个节点
printf("Doyouwanttoinputanotherdata?
(Y/N):
");
scanf("%c",&c);//输入Y或者y则继续申请节点空间
system("cls");
}
fflush(stdin);
}
//向链表添加尾节点
voidAddnode()
{
STU*p=NULL;
STU*pr=head;
p=(STU*)malloc(sizeof(STU));
if(p==NULL)
{
printf("Filetoapplythenode\n");
exit(0);
}
if(head==NULL)
{
head=p;//如果头指针为空,将p置为首节点
}
else
{
while(pr->next!
=NULL)
pr=pr->next;
pr->next=p;
}
printf("Inputthedata.......\n");
printf("Inputthestudent'sname\n");
scanf("%s",p->name);
printf("Inputthestudent'sclass\n");
scanf("%d",&p->classnumber);
printf("Inputthestudent'sscore\n");
printf("PleaseinputthescoreofChinese:
");
scanf("%d",p->score+0);
printf("PleaseinputthescoreofEnglish:
");
scanf("%d",p->score+1);
printf("PleaseinputthescoreofMath:
");
scanf("%d",p->score+2);
Total(p);
p->next=NULL;
fflush(stdin);
}
//计算每个学生成绩的总分和平均分
voidTotal(STU*p)
{
inti;
p->sum=0;
for(i=0;i<3;i++)
p->sum+=p->score[i];
p->average=(float)p->sum/3;
}
//删除一个学生信息
voiddelect()
{
STU*p=head;
STU*front,*current;
charName[20];
printf("Pleaseinputthestudent'sname:
");
scanf("%s",Name);
if(p==NULL)
printf("Thisisanemptylist!
!
!
\n");
else
{
if(strcmp(head->name,Name)==0)//判定删除对象是否为表头
{
front=head;
head=head->next;
free(front);
}
else
{
front=head;
current=head->next;
while(current!
=NULL&&strcmp(current->name,Name)!
=0)
{
front=current;
current=current->next;
}
if(current!
=NULL)
{
front->next=current->next;
free(current);
}
else
printf("Can'tfindthestudent!
!
!
\n");
}
}
}
//修改一个学生的信息
voidchange()
{
STU*p=head;
charName[20];
printf("Pleaseinputthestudent'sname:
");
scanf("%s",Name);
while(p!
=NULL&&strcmp(p->name,Name)!
=0)
p=p->next;
if(p!
=NULL)
{
printf("inputclassnumber:
");
scanf("%d",&p->classnumber);
printf("inputthescore:
");
printf("InputthescoreofChinese:
");
scanf("%d",p->score+0);
printf("InputthescoreofEnglish:
");
scanf("%d",p->score+1);
printf("InputthescoreofMath:
");
scanf("%d",p->score+2);
}
else
printf("Thenamedon'texist!
\n");
}
//输出不及格科目及学生名单
voidFailpass()
{
STU*p=head;
inti=0,j=0,k=0;
charstr[100]={'\0'},s[4]="**";
strcat(str,"ClassnumberNameChineseEnglishMath");
if(p==NULL)
printf("Thisisanemptylist!
\n");
else
{
while(p)
{
for(i=0,j=0;i<3;i++)
{
if(p->score[i]<60)
j++;//用来标记某个同学挂科数量
}
if(j!
=0)
k++;//用来标记学生链表中挂科人数,若j值不为0,则确定有挂科的人并计算挂科人数
p=p->next;
}
p=head;
if(k==0)//k值为0,则没有挂科人数,否则打印表头,输出挂科名单
{
printf("\n\t\tCongratuation!
!
!
Allpasstheexam!
!
!
\n");
}
else
{
printf("%s\n",str);
while(p)
{
for(i=0,j=0;i<3;i++)
{
if(p->score[i]<60)
j++;
}
if(j!
=0)
{
printf("%3d\t%10s",p->classnumber,p->name);
for(i=0;i<3;i++)
{
if(p->score[i]<60)
printf("%7d",p->score[i]);
else
printf("%7s",s);
}
printf("\n");
}
p=p->next;
}
}
}
}
//输出所有学生成绩名单
voidstudentlist()
{
STU*p=head;
charstr[100]={'\0'};
strcat(str,"classnumbername");
strcat(str,"ChineseEnglishMath");
strcat(str,"SumAverage");
if(p==NULL)
printf("It'sanemptylist!
!
!
");
else
{
printf("%s\n",str);
while(p!
=NULL)
{
printf("%3d\t%10s",p->classnumber,p->name);
printf("%8d%8d%8d",p->score[0],p->score[1],p->score[2]);
printf("%6d%6.2f",p->sum,p->average);
printf("\n");
p=p->next;
}
}
}
//按照班级输出成绩单
voidclasslist()
{
STU*p=head;
intnum,i=0;
charstr[100]={'\0'};
strcat(str,"name");
strcat(str,"ChineseEnglishMath");
strcat(str,"sumAverage");
printf("Pleaseinputtheclassnumberyouwanttosearch:
");
scanf("%d",&num);
if(head==NULL)
printf("Thisisanemptylist!
!
!
");
else
{
while(p!
=NULL)
{
if(p->classnumber==num)
i++;//用来标记,确定学生链表中是否存在你想要查找的班级
p=p->next;
}
p=head;
if(i!
=0)//若为0,则你想查找的班级不存在
{
printf("%s\n",str);
while(p!
=NULL)
{
if(p->classnumber==num)
{
printf("%s",p->name);
printf("%8d%8d%8d%5d",p->score[0],p->score[1],p->score[2],p->sum);
printf("%7.2f\n",p->average);
}
p=p->next;
}
}
else
printf("CannotfindthescoreofClass%d\n",num);
}
}
//决定数据是否按升序排序,a
intAscending(inta,intb)
{
returna
}
//决定数据是否按降序排序,a>b为真,则按降序排序
intDescending(inta,intb)
{
returna>b;
}
//交换两个整型数
voidIntSwap(int*pt1,int*pt2)
{
inttemp;
temp=*pt1;
*pt1=*pt2;
*pt2=temp;
}
/*交换两个实型数*/
voidFloatSwap(float*pt1,float*pt2)
{
floattemp;
temp=*pt1;
*pt1=*pt2;
*pt2=temp;
}
/*交换两个字符串*/
voidCharSwap(char*pt1,char*pt2)
{
chartemp[15];
strcpy(temp,pt1);
strcpy(pt1,pt2);
strcpy(pt2,temp);
}
//用交换法按总成绩由高到低排序
voidSortScore(int(*compare)(inta,intb))
{
STU*pt;
intflag=0,i;
do
{
flag=0;
pt=head;
if(head==NULL)
printf("Thisisanemptylist!
!
!
\n");
else
{
while(pt->next!
=NULL)
{
if((*compare)(pt->next->sum,pt->sum))
{
IntSwap(&pt->classnumber,&pt->next->classnumber);
CharSwap(pt->name,pt->next->name);
for(i=0;i<3;i++)
{
IntSwap(&pt->score[i],&pt->next->score[i]);
}
IntSwap(&pt->sum,&pt->next->sum);
FloatSwap(&pt->average,&pt->next->average);
flag=1;
}
pt=pt->next;
}
puts("afterSorted:
\n");
pt=head;
studentlist();
}
}while(flag);
}
//学生成绩排序
voidSort()
{
charchoice;
printf("pleaseinputyourchoice:
1-Ascending,2-Descending");
choice=getchar();
getchar();
switch(choice)
{
case'1':
SortScore(Ascending);
break;
default:
SortScore(Descending);
break;
}
}
voidmain()
{
STU*p=NULL;
charch;
system("COLOR5B");
while
(1)
{
ch=menu();
switch(ch)
{
case'1':
system("cls");
Applynode();//成绩输入模块
break;
case'2':
system("cls");
studentlist();//查询所有学生成绩单
system("pause");
system("cls");
break;
case'3':
system("cls");
classlist();//按班级查询学生成绩单
system("pause");
system("cls");
break;
case'4':
system("cls");
Failpass();//输出不及格科目及学生名单
system("pause");
system("cls");
break;
case'5':
system("cls");
Addnode();//增加输入一个学生信息
system("pause");
system("cls");
break;
case'6':
system("cls");
delect();//删除一个学生信息
system("pause");
system("cls");
break;
case'7':
system("cls");
change();//修改一个学生信息
system("pause");
system("cls");
break;
case'8':
system("cls");
Sort();//排序
system("pause");
system("cls");
break;
case'9':
exit(0);//退出
break;
default:
system("cls");
printf("Error!
!
!
Pleaseinputyourchoiceagain!
\n");
system("pause");
system("cls");
break;
}
}
}
心得体会:
1.哪些地方该加“”,{},自己必须要细心,及时打上。
不然面对庞大的代码要查找起来比较难;
2.程序要规范化,让操作人员看起来比较美观
3.指向函数的指针用起来比较生疏,还要多熟悉