学生成绩管理系统实验C语言文档格式.docx
《学生成绩管理系统实验C语言文档格式.docx》由会员分享,可在线阅读,更多相关《学生成绩管理系统实验C语言文档格式.docx(29页珍藏版)》请在冰点文库上搜索。
//成绩
floatsum;
//总分
floataverage;
//平均分
structSt*next;
};
六,程序结构流程图
七,模块功能
在结构流程图中已经给出。
八,实验结果
体会:
这个实验较上一个比起来更困难一些,不过经过和同学们的探讨和自己的努力最终完成了这个实验的基本要求,从中我受益匪浅,对以前学习的知识进行了进一步的巩固,对以后的学习有着很大的帮助。
附录:
#include<
stdio.h>
stdlib.h>
malloc.h>
string.h>
time.h>
conio.h>
voidInput(structSt*head,structSt*per);
//录入学生数据
intdel(structSt*head,charIDNumber[]);
//删除学生数据
voidaverage(structSt*head);
//按照平均分排序
voidlistprint(structSt*head);
//链表中学生信息输出
intsearchname(structSt*head,charFamilyName[],charGivenName[]);
//按照姓名查询信息
intfsave(structSt*head);
//将链表中的数据保存到文件中
intfread(structSt*head,FILE*fp);
//读取文件信息
intclasearch(structSt*head);
//按班级查找
intgrades(structSt*head);
//计算学生的总分和平均分
intmain()
{
printf("
\t\t$********************$$**********************$\t\t\t\n"
);
\t\t¥**************学生成绩管理系统*************¥\t\t\t\n"
structSt*head=(structSt*)malloc(sizeof(structSt));
head->
next=NULL;
FILE*fp=NULL;
inti=1;
while(i!
=9)
{
printf("
\t\t1.输入学生信息\n"
printf("
\t\t2.按学号从表中删除学生信息\n"
\t\t3.显示链表中所有记录\n"
\t\t4.按照姓名查找记录\n"
\t\t5.将链表中记录保存到文件中\n"
\t\t6.从文件中读入记录\n"
\t\t7.计算所有学生的总分和平均分\n"
\t\t8.按班级查询显示学生总分\n"
\t\t9.退出\n"
请选择:
"
scanf("
%d"
&
i);
switch(i){
case1:
system("
cls"
if(head==NULL){
printf("
数据出错!
exit(0);
}
else
{
structSt*per=(structSt*)malloc(sizeof(structSt));
per->
Input(head,per);
}
break;
case2:
system("
printf("
\t\t\t删除学生信息\n"
请输入要删除的学生的学号:
scanf("
%s"
IDNumber);
del(head,IDNumber);
break;
case3:
\t\t\t显示链表中学生信息\n"
listprint(head);
break;
case4:
\t\t\t学生信息查询\n"
请输入要查询学生的姓:
scanf("
FamilyName);
请输入要查询学生的名:
GivenName);
searchname(head,FamilyName,GivenName);
case5:
fsave(head);
case6:
fread(head,fp);
case7:
grades(head);
case8:
clasearch(head);
case9:
return1;
default:
}
}
}
voidInput(structSt*head,structSt*per)//录入学生数据
structSt*p=head->
next;
if(p!
=NULL)
{
while(p->
next!
p=p->
next;
p->
next=per;
else
head->
\t\t\t录入学生信息\n"
请输入学生的学号:
scanf("
per->
IDNumber);
请输入学生的姓:
FamilyName);
请输入学生的名:
GivenName);
do{
请输入学生的性别(0女,1男):
per->
sex);
if(1!
=per->
sex&
&
0!
sex)
您输入的性别有误!
\n"
}while(1!
structtm*ptm;
//当前时间获取
longts;
inty,m,d,h,n,s;
ts=time(NULL);
ptm=localtime(&
ts);
y=ptm->
tm_year+1900;
/*年*/
m=ptm->
tm_mon+1;
/*月*/
d=ptm->
tm_mday;
/*日*/
h=ptm->
tm_hour;
/*时*/
n=ptm->
tm_min;
/*分*/
s=ptm->
tm_sec;
/*秒*/
请输入出生年:
BirthYear);
if(per->
BirthYear>
y)
您输入的年份有错请重新输入!
}while(per->
y);
请输入出生月:
BirthMonth);
BirthMonth>
12)
您输入的月份份有错请重新输入!
12);
请输入出生日:
BirthDay);
BirthDay>
31)
您输入的日期有错请重新输入!
31);
外语:
%f"
score[0]);
高数:
score[1]);
C语言:
score[2]);
马哲:
score[3]);
per->
average=(per->
score[0]+per->
score[1]+per->
score[2]+per->
score[3])/4;
sum=per->
score[0]+per->
score[1]+per->
score[2]+per->
score[3];
intdel(structSt*head,charIDNumber[])//删除学生数据
if(head->
next==NULL)
数据列表为空,无法删除!
return0;
structSt*p=head->
structSt*pfront=head;
while(p!
=NULL&
strcmp(p->
IDNumber,IDNumber)!
=0)
{
pfront=p;
if(p==NULL)
记录中没有发现您要删除的人\n"
else
pfront->
next=p->
free(p);
该生信息已删除\n"
return1;
voidaverage(structSt*head)//按照平均分将列表排序
structSt*p,*q,*m,*n;
structSt*temp1;
NOLINKLIST!
!
p=head;
q=head->
while(q->
m=p->
n=q->
temp1=m;
while(temp1->
{
if(temp1->
next->
average<
q->
average&
temp1->
n->
average)
m=temp1;
n=temp1->
temp1=temp1->
}/*此循环用于找到基准(q)以后的序列的最小的节点*/
if(m!
=p->
next||(m==p->
next&
m->
average>
n->
average))
{
p->
next=n;
p=n;
m->
next=q;
m=q;
q=q->
n=n->
}/*此条件用于交换两个节点*/
p=p->
}/*此条件用于没有找到最小值时的p,q后移操作*/
}/*外循环用于从前往后扫描,通过移动p,q指针实现*/
voidlistprint(structSt*head)//链表中学生信息输出
average(head);
学号:
%s姓氏:
%s名字:
%s性别:
%d\n出生年:
%d月:
%d日:
%d\n"
p->
IDNumber,p->
FamilyName,p->
GivenName,p->
sex,p->
BirthYear,p->
BirthMonth,p->
%f高数:
%fc语言:
%f马哲:
\n%f总分:
%f平均分:
%f\n"
score[0],p->
score[1],p->
score[2],p->
score[3],p->
sum,p->
average);
}
链表为空,请先输入数据\n"
intsearchname(structSt*head,charFamilyName[],charGivenName[])//按照姓名查询信息
数据列表为空,无法查询!
if(strcmp(p->
FamilyName,FamilyName)==0&
GivenName,GivenName)==0)
break;
记录中并没有发现您要找的人!
%fc语言:
\n%f总分:
intfsave(structSt*head)//将链表中的数据保存到文件中
{printf("
\t\t\t文件保存\n"
FILE*fp;
if((fp=fopen("
grades.txt"
"
wb+"
))==NULL)
文件无法打开!
structSt*p=head->
fwrite(p,sizeof(structSt),1,fp);
fclose(fp);
链表已经写入文件\n"
intfread(structSt*head,FILE*fp)//读取文件信息
\t\t\t文件读取\n"
structSt*p,*p1;
p=p1=(structSt*)malloc(sizeof(structSt));
rb"
文件读取错误!
{printf("
正在读取...\n"
while(!
feof(fp))
p=(structSt*)malloc(sizeof(structSt));
fread(p,sizeof(structSt),1,fp);
if(feof(fp))
next==NULL)
head->
next=p;
p1->
p1=p;
p1->
listprint(head);
文件已读完\n"
intgrades(structSt*head)//计算有学生的总分和平均分
\t\t\t计算学生的总分和平均分\n"
structSt*p=head->
floattotalScore[4]={0,0,0,0};
floattotalAverage[4]={0,0,0,0};
intamount=0;
数据列表为空,无法计算所有学生的总分和平均分!
{
totalScore[0]+=p->
score[0];
totalScore[1]+=p->
score[1];
totalScore[2]+=p->
score[2];
totalScore[3]+=p->
amount++;
totalAverage[0]=totalScore[0]/amount;
totalAverage[1]=totalScore[1]/amount;
totalAverage[2]=totalScore[2]/amount;
totalAverage[3]=totalScore[3]/amount;
记录中共有%d个学生的信息,各科总分和平均分如下:
amount);
外语总分为:
%f\t\t外语平均分:
totalScore[0],totalAverage[0]);
高数总分为:
%f\t\t高数平均分:
totalScore[1],totalAverage[1]);
C语言总分为:
%f\t\tC语言平均分:
totalScore[2],totalAverage[2]);
马哲总分为:
%f\t\t马哲平均分:
totalScore[3],totalAverage[3]);
平均分90分以上的学生信息:
p=head->
while(p!
=NULL)
{
if(p->
average>
=90)
%d出生年:
p=p->
平均分80~90分的学生信息: