C语言课程设计学生成绩管理系统完美运行代码Word格式文档下载.docx
《C语言课程设计学生成绩管理系统完美运行代码Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《C语言课程设计学生成绩管理系统完美运行代码Word格式文档下载.docx(21页珍藏版)》请在冰豆网上搜索。
voidPrintTablHeader();
voidPrintAll(Student*a,intn);
intSearchByNo(Student*a,intn,charno[]);
voidSearchByname(Student*a,intn,charname[]);
voidSortByTotal(Student*a,intn);
voidSortByMcu(Student*a,intn);
voidSortByMath(Student*a,intn);
voidSortByEnglish(Student*a,intn);
voidSort(Student*a,intn,intcourse);
intDeleteByNo(Student*a,intn,charno[]);
voidsave(Student*a,intn);
voidenglish(Studentstu[],intn);
voidmath(Studentstu[],intn);
voidmcu(Studentstu[],intn);
voidenglishaver(Studentstu[],intn);
voidmathaver(Studentstu[],intn);
voidmcuaver(Studentstu[],intn);
voidtotalaver(Studentstu[],intn);
intload(Studentt[]);
//符号常量和变量说明
#defineN100//学生最大人数
intlength=0;
//学生实际人数
intitem;
charch;
#defineENGLISH0//英语课程
#defineMATH1//数学课程
#defineMCU2//计算机课程
#defineTOTAL3//总分
Studentstu[N]=//学生结构体数组,全局变量
{"
10"
"
王安"
男"
{1991,2,14},{15,55,31}},
11"
张羽"
女"
{1992,9,22},{92,83,58}},
12"
李明"
{1992,2,18},{60,65,72}},
13"
"
李江"
{1992,12,14},{100,50,78}},
14"
李楠"
{1992,6,29},{90,52,76}},
15"
张萍"
{1991,8,9},{57,78,92}},
16"
李文"
{1992,10,4},{100,80,60}},
17"
张雨"
{1991,12,14},{60,90,80}}
//6.2主函数及各功能函数
voidInit()
inti;
length=8;
for(i=0;
i<
length;
i++)
{
stu[i].sco.total=stu[i].sco.english+stu[i].sco.math+stu[i].sco.mcu;
}
}
voidMenu()
printf("
==================欢迎登录学生成绩管理系统==============\n"
);
************************************\n"
*1--按学号查询学生信息*\n"
*2--按姓名查询学生信息*\n"
*3--查询所有学生信息*\n"
*4--根据单科成绩进行排序*\n"
*5--根据总分进行排序*\n"
*6--添加学生信息*\n"
*7--删除学生信息*\n"
*8--修改学生信息*\n"
*9--保存学生信息文件*\n"
*10--读入学生信息文件*\n"
*11--查询不及格学生信息*\n"
*12--查询平均成绩*\n"
*0--退出*\n"
请选择:
"
voidPrint(Student*p)
%s\t%s\t%s\t%d-%d-%d\t%3.1f\t%3.1f\t%3.1f\t%3.1f"
p->
no,p->
name,p->
sex,
birth.year,p->
birth.month,p->
birth.day,
sco.english,p->
sco.math,p->
sco.mcu,p->
sco.total);
voidPrintTablHeader()
学号\t姓名\t性别\t生日\t\t英语\t数学\t计算机\t总分\n"
voidPrintAll(Student*a,intn)
目前学生总人数为:
%d\n"
length);
PrintTablHeader();
n;
{Print(&
a[i]);
//调用Printf函数输出第i个学生信息
printf("
\n"
intSearchByNo(Student*a,intn,charno[])//按学号查找学生成绩信息
intp=-1;
if(strcmp(a[i].no,no)==0)
{
p=i;
break;
}
returnp;
voidSearchByname(Student*a,intn,charname[])//按姓名查找学生成绩信息
intflag=0;
for(i=0;
if(strcmp(a[i].name,name)==0)
flag=1;
Print(&
printf("
}
if(flag==0)printf("
查询失败!
voidSortByEnglish(Student*a,intn)//根据英语成绩进行排序
inti,j;
//循环变量
floatmaxval;
//用于临时保存最大值
intmaxpos;
//用于临时保存最大值的下标
Studenttemp;
//临时变量
//总共需要N-1次选择和交换
n-1;
maxval=a[i].sco.english;
maxpos=i;
//在无序区寻找最大值
for(j=i;
j<
j++)
if(a[j].sco.english>
maxval)
{
maxval=a[j].sco.english;
maxpos=j;
}
if(maxpos!
=-1)
temp=a[maxpos];
a[maxpos]=a[i];
a[i]=temp;
}
voidSortByMath(Student*a,intn)//根据数学成绩进行排序
maxval=a[i].sco.math;
if(a[j].sco.math>
maxval=a[j].sco.math;
=i)
voidSortByMcu(Student*a,intn)//根据计算机成绩进行排序
maxval=a[i].sco.mcu;
if(a[j].sco.mcu>
maxval=a[j].sco.mcu;
voidSortByTotal(Student*a,intn)//根据学生总成绩进行排序
maxval=a[i].sco.total;
if(a[j].sco.total>
maxval=a[j].sco.total;
if(maxpos!
voidenglish(Studentstu[],intn)//查询英语成绩不及格学生信息
inti=0;
for(i=0;
if(stu[i].sco.english<
60)
\t学生证号:
%-15s姓名:
%-15s英语分数:
%-15g\n\n"
stu[i].no,stu[i].name,stu[i].sco.english);
voidmath(Studentstu[],intn)//查询数学成绩不及格学生信息
if(stu[i].sco.math<
%-15s数学分数:
stu[i].no,stu[i].name,stu[i].sco.math);
voidmcu(Studentstu[],intn)//查询计算机成绩不及格学生信息
if(stu[i].sco.mcu<
%-15s计算机分数:
stu[i].no,stu[i].name,stu[i].sco.mcu);
voidSort(Student*a,intn,intcourse)
switch(course)
caseENGLISH:
SortByEnglish(a,n);
break;
caseMATH:
SortByMath(a,n);
caseMCU:
SortByMcu(a,n);
caseTOTAL:
SortByTotal(a,n);
default:
SortByTotal(a,n);
/*增加学生信息*/
intAppend(Student*a,intn)
intpos;
if(n>
=N)
returnn;
while
(1)
请输入学号:
scanf("
%s"
&
a[n].no);
pos=SearchByNo(a,n,a[n].no);
if(pos!
=-1)printf("
学号已经存在,请重新输入!
elsebreak;
请输入姓名:
a[n].name);
请输入性别:
a[n].sex);
请输入出生年份:
%d"
a[n].birth.year);
请输入出生月份:
a[n].birth.month);
请输入出生日期:
a[n].birth.day);
请输入英语成绩:
%f"
a[n].sco.english);
请输入数学成绩:
a[n].sco.math);
请输入计算机成绩:
a[n].sco.mcu);
a[n].sco.total=a[n].sco.english+a[n].sco.math+a[n].sco.mcu;
n++;
returnn;
intDeleteByNo(Student*a,intn,charno[])
intpos=SearchByNo(a,n,no);
if(pos==-1)
学号不存在,请重新输入!
//减少学生人数,并返回该值
if(pos==n-1)
n--;
for(i=pos;
a[i]=a[i+1];
/*修改函数*/
intModifyByNo(Student*a,intn,charno[])
intp;
charsno[15];
if(pos==-1)
{
该学生不存在!
请输入学号:
sno);
p=SearchByNo(a,n,sno);
if(p==-1||p==pos)//两种情况,1.下表不存在2.不修改下表
strcpy(a[pos].no,sno);
elseprintf("
学生学号已存在,请重新输入!
a[pos].name);
a[pos].sex);
a[pos].birth.year);
a[pos].birth.month);
a[pos].birth.day);
a[pos].sco.english);
a[pos].sco.math);
a[pos].sco.mcu);
voidsave(Student*a,intn)//保存函数
FILE*fp;
if((fp=fopen("
studentinformation.txt"
wb"
))==NULL)
不能打开文件!
exit
(1);
\n保存文件\n"
fprintf(fp,"
n);
//将记录数写入文件
\r\n"
//将换行符号写入文件
i++)
{fprintf(fp,"
a[i].no,a[i].name,a[i].sex,a[i].birth.year,a[i].birth.month,a[i].birth.day,a[i].sco.english,a[i].sco.math,a[i].sco.mcu,a[i].sco.total);
//写入记录
fprintf(fp,"
fclose(fp);
成功保存文件!
//**************文件的读入*****************//
intload(Studentt[])
inti,n;
rb+"
))==NULL)//打开文件
fscanf(fp,"
n);
//读入记录数
{fread(fp,"
%s\t%s\t%s\t%d%d%d\t%3.1f\t%f\t%f\t%f"
t[i].no,t[i].name,t[i].sex,&
t[i].birth.year,&
t[i].birth.month,&
t[i].birth.day,&
t[i].sco.english,&
t[i].sco.math,&
t[i].sco.mcu,&
t[i].sco.total);
//读入记录
}
成功读入记录!
voidenglishaver(Studentstu[],intn)//英语平均成绩
inti;
doubleaver1,sum1=0;
for(i=0;
sum1+=stu[i].sco.english;
aver1=1.0*sum1/n;
英语平均分:
%.2f\n\n"
aver1);
voidmathaver(Studentstu[],intn)//数学平均成绩
sum1=sum1+stu[i].sco.math;
aver1=sum1/n;
数学平均分:
%.2f\n\n"
voidmcuaver(Studentstu[],intn)//计算机平均成绩
doubleaver1,sum1=0;
n+1;
sum1+=stu[i].sco.mcu;
计算机平均分:
voidtotalaver(Studentstu[],intn)//总平均成绩
inti;
doubleaver1,sum;
sum=stu[i].sco.mcu+stu[i].sco.english+stu[i