C语言学生成绩管理系统源代码Word格式文档下载.docx
《C语言学生成绩管理系统源代码Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《C语言学生成绩管理系统源代码Word格式文档下载.docx(16页珍藏版)》请在冰豆网上搜索。
voidsave();
/*保存数据函数*/
voidread();
/*读出数据函数*/
voiddel_file();
/*删除文件函数*/
voidmodify();
/*修改文件函数*/
intnow_no=0;
structstudent//定义学生信息
{
intno;
//学号
charname[20];
//姓名
charsex[4];
//性别
floatscore1;
//成绩1
floatscore2;
//成绩2
floatscore3;
//成绩3
floatsort;
//排序成绩
floatave;
//平均分
floatsum;
//总分
};
voidmain()
{
inth,flag1,flag2;
charname[20]="
xdxy"
password[10]="
700619"
;
charperson[20],password1[10];
printf("
\t\t********欢迎进入学生成绩管理系统!
********\n\n"
);
\t\t\t用户登录\n\n"
for(h=0;
h!
=5;
)
{
printf("
\t\t\t\t用户名:
"
gets(person);
flag1=strcmp(person,name);
\t\t\t\t密码:
gets(password1);
flag2=strcmp(password,password1);
if(flag1==0&
&
flag2==0)
{
\t\t\t\t登陆成功!
\n\n"
menu();
break;
}
else
\t\t\t用户名或密码错误!
printf("
\t\t\t请注意:
您还剩%d次机会!
4-h);
h++;
}
if(h=5)
对不起,您输入的用户名或密码有误,已被强制退出。
\n"
}
structstudentstu[MAX],*p;
voidmenu()/*主函数*/
intas;
charch;
do{
\n\n\n\n\t\t****&
****&
****"
start:
\n\n\n\n\t\t\t欢迎使用学生成绩管理系统\n"
\n\n\n\n\t\t******************按任意键继续********************"
ch=getch();
}
while(!
ch);
system("
cls"
/*以下为功能选择模块*/
do
{
\n\t\t\t\t1.录入学生信息\n\t\t\t\t2.显示学生总成绩信息\n\t\t\t\t3.对总成绩排序\n\t\t\t\t4.显示学生单科成绩排序\n\t\t\t\t5.添加学生信息\n\t\t\t\t6.删除学生信息\n\t\t\t\t7.修改学生信息\n\t\t\t\t8.查询学生信息\n\t\t\t\t9.从文件读入学生信息\n\t\t\t\t10.删除文件中学生信息\n\t\t\t\t11.保存学生信息\n\t\t\t\t12.退出\n"
\t\t\t\t选择功能选项(输入所选功能前的数字):
fflush(stdin);
/*可用可不用,用于清除缓存防止下次用scanf输入时出现错误*/
scanf("
%d"
&
as);
switch(as)
case1:
system("
input();
case2:
display();
case3:
sort();
case4:
display1();
case5:
insert();
case6:
del();
case7:
modify();
case8:
find();
case9:
read();
case10:
del_file();
case11:
save();
case12:
exit"
exit(0);
default:
gotostart;
}while
(1);
/*while
(1),1表示真,所以while
(1)表示永远循环下去*/
/*至此功能选择模块结束*/
voidinput()/*学生信息录入模块*/
inti=0;
\t\t\t\t1.录入学生信息\n输入第%d个学生的信息\n"
i+1);
\n输入8位的学生学号:
%u"
stu[i].no);
\n输入学生姓名:
gets(stu[i].name);
\n输入学生性别:
gets(stu[i].sex);
\n输入学生成绩1:
%f"
stu[i].score1);
\n输入学生成绩2:
stu[i].score2);
\n输入学生成绩3:
stu[i].score3);
i++;
now_no=i;
是否继续输入?
(Y/N)"
while(ch!
='
n'
ch!
N'
}
voidsort()/*排序数据函数*/
structstudenttemp;
inti,j;
average();
for(i=1;
i<
now_no;
i++)
for(j=1;
j<
=now_no-i;
j++)
if(stu[j-1].ave<
stu[j].ave)
temp=stu[j];
stu[j]=stu[j-1];
stu[j-1]=temp;
排序已完成进入功能2可进行显示\n"
pause"
voidsort1()/*排序数据函数*/
if(stu[j-1].score1<
stu[j].score1)
voidsort2()/*排序数据函数*/
if(stu[j-1].score2<
stu[j].score2)
voidsort3()/*排序数据函数*/
if(stu[j-1].score3<
stu[j].score3)
voiddisplay()/*显示数据函数*/
inti;
charas;
\t\t\t班级学生信息列表\n"
\t学号\t姓名\t性别\t成绩1\t成绩2\t成绩3\t平均值\n"
for(i=0;
now_no&
stu[i].name[0];
\t%u%s\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n"
stu[i].no,stu[i].name,stu[i].sex,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].ave);
\t\t\t按任意键返回主菜单"
as=getch();
voiddisplay1()/*显示数据函数*/
\t\t\t班级学生score1成绩排序\n"
\t学号\t姓名\t性别\t成绩1\n"
sort1();
\t%u%s\t%s\t%.2f\t\n"
stu[i].no,stu[i].name,stu[i].sex,stu[i].score1);
\t\t\t班级学生score2成绩排序\n"
\t学号\t姓名\t性别\t成绩2\n"
sort2();
stu[i].no,stu[i].name,stu[i].sex,stu[i].score2);
\t\t\t班级学生score3成绩排序\n"
\t学号\t姓名\t性别\t成绩3\n"
sort3();
stu[i].no,stu[i].name,stu[i].sex,stu[i].score3);
voidinsert()/*插入数据函数*/
\n\t\t输入新插入学生信息\n"
\n输入学生学号:
stu[now_no].no);
gets(stu[now_no].name);
gets(stu[now_no].sex);
stu[now_no].score1);
stu[now_no].score2);
stu[now_no].score3);
now_no=now_no+1;
voiddel()/*删除数据函数*/
{unsignedlonginum;
输入要删除学生的学号:
inum);
if(stu[i].no==inum)
if(i==now_no)now_no-=1;
else
stu[i]=stu[now_no-1];
now_no-=1;
voidsave()/*保存数据函数*/
FILE*fp;
charfilepath[20];
输入要保存的文件路径:
gets(filepath);
if((fp=fopen(filepath,"
w"
))==NULL)
\n保存失败!
stu[i].sum=stu[i].score1+stu[i].score2+stu[i].score3;
stu[i].ave=stu[i].sum/3;
fprintf(fp,"
fclose(fp);
学生信息已保存在%s中!
filepath);
voidfind()/*查询函数*/
charstr[20],as;
输入要查询的学生姓名:
gets(str);
if(!
strcmp(stu[i].name,str))
\t学号\t\t姓名\t性别\t成绩1\t成绩2\t成绩3\t平均值\n"
\t%u\t%s\t%s\t%.2f\t%.2f\t%.2f\t%.2f\n"
voidaverage()/*求平均数*/
voidmodify()/*修改数据函数*/
charstr[20];
输入要修改的学生姓名:
\n\t\t输入修改后学生信息\n"
voidread()
输入要读入的文件路径:
r"
找不到%s文件!
now_no=0;
MAX&
!
feof(fp);
fscanf(fp,"
\t%d\t%s\t%s\t%f\t%f\t%f\t%f\n"
stu[i].no,stu[i].name,stu[i].sex,&
stu[i].score1,&
stu[i].score2,&
stu[i].score3,&
stu[i].ave);
now_no++;
保存的在文件%s中的所有信息已经读入!
/*按任意键继续*/
voiddel_file()
输入要删除的文件路径:
fp=fopen(filepath,"
保存的在文件%s中的所有信息已经删除!