班级成绩管理系统
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
/*定义学生结构体*/
struct Student
{
char ID[20];
char Name[20];
float yuwen;
float shuxue;
float yingyu;
float Average;
};
/*声明学生数组及学生数量*/
struct Student students[1000];
int num=0;
/*求平均值*/
float Avg(struct Student stu)
{
return (stu.yuwen+stu.shuxue+stu.yingyu)/3; }
/*通过学号返回数组下标*/
int Student_SearchByIndex(char id[])
{
int i;
for (i=0;i<num;i++)
{
if (strcmp(students[i].ID,id)==0)
{
return i;
}
}
return-1;
}
/*显示单条学生记录*/
void Student_DisplaySingle(int index)
{
printf("%10s%10s%8s%8s%8s%10s\n","学号","姓名","成绩","成绩","成绩","平均成绩");
printf("-------------------------------------------------------------\n");
printf("%10s%10s%8.2f%8.2f%8.2f%10.2f\n",students[index].ID,students[ index].Name,
students[index].yuwen,students[index].shuxue,students[index].yingyu,s tudents[index].Average);
}
/*学生成绩录入*/
void Student_add()
{
while(1)
{
printf("请输入学号:");
scanf("%s",&students[num].ID);
printf("请输入姓名:");
scanf("%s",&students[num].Name);
printf("请输入语文成绩:");
scanf("%f",&students[num].yuwen);
printf("请输入数学成绩:");
scanf("%f",&students[num].shuxue);
printf("请输入英语成绩:");
scanf("%f",&students[num].yingyu);
students[num].Average=Avg(students[num]);
num++;
getchar();
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*显示学生信息*/
void Student_Display()
{
int i;
printf("%10s%10s%8s%8s%8s%10s\n","学号","姓名","成绩","成绩","成绩","平均成绩");
printf("-------------------------------------------------------------\n");
for (i=0;i<num;i++)
{
printf("%10s%10s%8.2f%8.2f%8.2f%10.2f\n",students[i].ID,students[i].N ame,
students[i].yuwen,students[i].shuxue,students[i].yingyu,students[i].A verage);
}
}
/*按平均值排序*/
void Student_SortByAverage()
{
int i,j;
struct Student tmp;
for (i=0;i<num;i++)
{
for (j=1;j<num-i;j++)
{
if (students[j-1].Average<students[j].Average)
{
tmp=students[j-1];
students[j-1]=students[j];
students[j]=tmp;
}
}
}
}
/*修改学生信息*/
void Student_Modify()
{
int i;
char str1[15],str2[15];
printf("\t\t\t 管理员登陆\n");
for (i=0;i<100000000;i++)
{
printf("\t\t\t请输入用户名:");
gets(str1);
printf("\t\t\t请输入密码:");
gets(str2);
if ((strcmp(str1,"123")==0&&strcmp(str2,"123")==0)) {printf("\t\t\t正确!\n");break;}
else
printf("\t\t\t用户名密码错误,请重试!
\n");continue;
}
while(1)
{
char id[20];
int index;
printf("请输入要修改的学生的学号:");
scanf("%s",&id);
getchar();
index=Student_SearchByIndex(id);
if (index==-1)
{
printf("学生不存在!\n");
}
else
{
printf("你要修改的学生信息为:\n");
Student_DisplaySingle(index);
printf("-- 请输入新值--\n");
printf("请输入学号:");
scanf("%s",&students[index].ID);
getchar();
printf("请输入姓名:");
scanf("%s",&students[index].Name);
getchar();
printf("请输入语文成绩:");
scanf("%f",&students[index].yuwen);
getchar();
printf("请输入数学成绩:");
scanf("%f",&students[index].shuxue);
getchar();
printf("请输入英语成绩:");
scanf("%f",&students[index].yingyu);
getchar();
students[index].Average=Avg(students[index]); }
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*成绩统计*/
void student_statistics()
{
int i;
struct Student tmp;
for (i=1;i<num;i++)
{
if (students[i-1].yuwen>students[i].yuwen)
{
tmp=students[i-1];
students[i-1]=students[i];
students[i]=tmp;
}
}
printf("语文成绩最高的是:\n");
printf("%10s%10s%10s%10s%10s%10s\n","学号","姓名","语文成绩","数学成绩","英语成绩","平均成绩");
printf("-------------------------------------------------------------\n");
printf("%10s%10s%10.2f%10.2f%10.2f%10.2f\n",students[num-1].ID,studen ts[num-1].Name,
students[num-1].yuwen,students[num-1].shuxue,students[num-1].yingyu,s tudents[num-1].Average);
printf("-------------------------------------------------------------\n");
for (i=1;i<num;i++)
{
if (students[i-1].shuxue>students[i].shuxue)
{
tmp=students[i-1];
students[i-1]=students[i];
students[i]=tmp;
}
}
printf("数学成绩最高的是:\n");
printf("%10s%10s%10s%10s%10s%10s\n","学号","姓名","语文成绩","数学成绩","英语成绩","平均成绩");
printf("-------------------------------------------------------------\n");
printf("%10s%10s%10.2f%10.2f%10.2f%10.2f\n",students[num-1].ID,studen ts[num-1].Name,
students[num-1].yuwen,students[num-1].shuxue,students[num-1].yingyu,s tudents[num-1].Average);
printf("-------------------------------------------------------------\n");
for (i=1;i<num;i++)
{
if (students[i-1].yingyu>students[i].yingyu)
{
tmp=students[i-1];
students[i-1]=students[i];
students[i]=tmp;
}
}
printf("英语成绩最高的是:\n");
printf("%10s%10s%10s%10s%10s%10s\n","学号","姓名","语文成绩","数学成绩","英语成绩","平均成绩");
printf("-------------------------------------------------------------\n");
printf("%10s%10s%10.2f%10.2f%10.2f%10.2f\n",students[num-1].ID,studen ts[num-1].Name,
students[num-1].yuwen,students[num-1].shuxue,students[num-1].yingyu,s tudents[num-1].Average);
printf("-------------------------------------------------------------\n");
}
/*主程序*/
main()
{
int choice;
while(1)
{
/*主菜单*/
printf("\n\t\t\t------ 班级成绩管理系统------\t\t\t\n"); printf("\t\t\t1. 学生成绩录入\t\t\t\n");
printf("\t\t\t2. 学生成绩显示\t\t\t\n");
printf("\t\t\t3. 按学生平均成绩排序\t\t\t\n");
printf("\t\t\t4. 学生成绩修改\t\t\t\n");
printf("\t\t\t5. 学生成绩统计\t\t\t\n");
printf("\t\t\t6.退出系统\t\t\t\n");
printf("\t\t\t请选择(1-6):");
scanf("%d",&choice);
getchar();
switch(choice)
{
case 1:Student_add();break;
case 2:Student_Display();break;
case 3:Student_SortByAverage();
Student_Display();
break;
case 4:Student_Modify(); break;
case 5:student_statistics();break;
case 6:exit(0);break;
}
}
}。