由于笔者能力所限所以只是简易程序,供初学者学习:
#include <stdio.h> #include <stdlib.h> #include<string.h> #define n 100//此处自己更改 void face(void); void choice(int m,char name[][20],double math[],double english[],double Clanguage[]); void input(char name[][20],double math[],double english[],double Clanguage[]); void ouput(char name[][20],double math[],double english[],double Clanguage[]); void sort_ouput(char name[][20],double math[],double english[],double Clanguage[]); void find_my(char name[][20],double math[],double english[],double Clanguage[]); void jige(char name[][20],double math[],double english[],double Clanguage[]); void averange(char name[][20],double math[],double english[],double Clanguage[]); int main() { char name[n][20]; double math[n],english[n],Clanguage[n]; face(); int m; while(1){ scanf("%d",&m); if(m==0) break; else choice(m,name,math,english,Clanguage); } return 0; } void face() { printf("欢迎光临学生成绩管理系统,很高兴能为你服务\n"); puts("*************************************************"); puts("The menu is as follows:"); puts("学生姓名与各科成绩的输入,请输入1来获得帮助"); puts("学生姓名与各科成绩的输出,请输入2来获得帮助"); puts("按学生总成绩从低到高排序并输出,请输入3来获得帮助"); puts("按学生姓名来查找学生成绩,请输入4来获得帮助"); puts("输出及格的学生姓名和成绩,请输入5来获得帮助"); puts("计算学生平均成绩并且输出,请输入6来获得帮助"); printf("说明:成绩以百分制,及格分数为\n每科分数都达到六十分来计算\n"); printf("输入输出格式为:Name Math English Clanguage\n"); puts("请输入0来关闭学生成绩管理系统 $*(0@0)*$ thank you"); } void choice(int m,char name[][20],double math[],double english[],double Clanguage[]) { switch(m) { case 1:input(name,math,english,Clanguage);break; case 2:ouput(name,math,english,Clanguage);break; case 3:sort_ouput(name,math,english,Clanguage);break; case 4:find_my(name,math,english,Clanguage);break; case 5:jige(name,math,english,Clanguage);break; case 6:averange(name,math,english,Clanguage);break; } } void input(char name[n][20],double math[],double english[],double Clanguage[]) { int i; for(i=0;i<n;i++){ scanf("%s %lf %lf %lf",&name[i],&math[i],&english[i],&Clanguage[i]); } } void ouput(char name[n][20],double math[],double english[],double Clanguage[]) { int i; printf("学生成绩如下:\n"); for(i=0;i<n;i++){ printf("%s %.2lf %.2lf %.2lf\n",name[i],math[i],english[i],Clanguage[i]); } } void sort_ouput(char name[n][20],double math[],double english[],double Clanguage[]) { double max[n]; int i; printf("学生成绩排名如下:\n"); for(i=0;i<n;i++){ max[i]=math[i]+english[i]+Clanguage[i]; } int j,k; double t; char change[20]; for(i=0;i<n-1;i++) { k=i; for(j=i+1;j<n;j++) { if(max[j]<max[k]) k=j; } if(k!=i) { t=max[i]; strcpy(change,name[i]); max[i]=max[k]; strcpy(name[i],name[k]); max[k]=t; strcpy(name[k],change); } } for(i=0;i<n;i++){ printf("%s %.2f\n",name[i],max[i]); } } void find_my(char name[][20],double math[],double english[],double Clanguage[]) { char names[20]; printf("请输入你要查找的人的名字:"); int flag=0; scanf("%s",names); for(int i=0;i<n;i++){ if(strcmp(names,name[i])==0){ printf("他的成绩:Math %.2lf English %.2lf Clanguage %.2lf",math[i],english[i],Clanguage[i]); flag=1; } } if(flag==0) printf("查无此人,确保正确后输入!\n"); } void jige(char name[][20],double math[],double english[],double Clanguage[]) { printf("及格学生如下:\n"); int flag=0; int i; for(i=0;i<n;i++) { if(math[i]>=60) flag+=1; if(english[i]>=60) flag+=1; if(Clanguage[i]>=60) flag+=1; if(flag==3) printf("%s Math%.2lf English%.2lf Clanguage%.2lf",name[i],math[i],english[i],Clanguage[i]); else flag=0; } } void averange(char name[][20],double math[],double english[],double Clanguage[]) { printf("学生平均成绩:\n"); double aver=0; int i=0; double m=0,e=0,c=0; for(i=0;i<n;i++) { aver+=math[i]+english[i]+Clanguage[i]; m+=math[i]; e+=english[i]; c+=Clanguage[i]; } printf("个体综合平均:%.4f\n",aver/n); printf("Math平均:%.4f\n",m/n); printf("English平均:%.4f\n",e/n); printf("Clanguage平均:%.4f\n",c/n); }