<span style="font-size:18px;">#include<stdio.h>
#include<string.h>
double EPS = 1e-5;
int Add_n=0; //记录学生人数
struct student{ //学生信息数据结构 *
char SID[15]; //学生编号
int CID,T,Total; //班级编号,年级排名,总分
char Name[15]; //学生名字
int S[4]; //语,数,英,编程成绩
double Average; //平均分
}My[1000];
void HAHA_printf() //输出主菜单内容 *
{
printf("Welcome to Student Performance Management System (SPMS).\n\n");
printf("1 - Add\n");
printf("2 - Remove\n");
printf("3 - Query\n");
printf("4 - Show ranking\n");
printf("5 - Show Statistics\n");
printf("0 - Exit\n\n");
}
void Add() //存储学生信息 *
{
while(1){
int f=1; //f=1表示该SID没重复
printf("Please enter the SID, CID, name and four scores. Enter 0 to finish.\n");
scanf("%s",My[Add_n].SID);
if(strcmp(My[Add_n].SID,"0")==0)
break;
scanf("%d %s %d %d %d %d",&My[Add_n].CID,My[Add_n].Name,&My[Add_n].S[0],&My[Add_n].S[1],&My[Add_n].S[2],&My[Add_n].S[3]);
My[Add_n].Total=My[Add_n].S[0]+My[Add_n].S[1]+My[Add_n].S[2]+My[Add_n].S[3]; //总分
My[Add_n].Average= My[Add_n].Total/4.0; //平均分
for(int i=0;i<Add_n;i++){
if(strcmp(My[Add_n].SID,My[i].SID)==0) //如果查到学号重复,输出 提示:Duplicated SID.并且不记录
{
printf("Duplicated SID.\n");
f=0; //SID重复,不存储
break;
}
}
if(f==1)
Add_n++;
}
}
void Remove() //删除学生信息*
{
while(1){
char s[20];
printf("Please enter SID or name. Enter 0 to finish.\n");
scanf("%s",s);
if(strcmp(s,"0")==0)
break;
int i,sum=0;
strcpy(My[Add_n].SID,"0");
strcpy(My[Add_n].Name,"0");
for(i=0;i<Add_n;i++)
{
if(strcmp(My[i].SID,s)==0||strcmp(My[i].Name,s)==0)
{
for(int j=i;j<Add_n;j++) //删除学生信息,往前移一个
{
strcpy(My[j].SID,My[j+1].SID);
My[j].CID=My[j+1].CID;
strcpy(My[j].Name,My[j+1].Name);
My[j].S[0]=My[j+1].S[0];
My[j].S[1]=My[j+1].S[1];
My[j].S[2]=My[j+1].S[2];
My[j].S[3]=My[j+1].S[3];
My[j].Total=My[j+1].Total;
My[j].Average=My[j+1].Average;
}
sum++;
i--;
}
}
Add_n-=sum;
printf("%d student(s) removed.\n",sum);
}
}
void Query()
{
for(int i=0;i<Add_n;i++)
{
My[i].T=1; //年级排名
for(int j=0;j<Add_n;j++)
{
if(My[i].Total<My[j].Total) //知道到比自己打的就加一
My[i].T++;
}
}
while(1){
char s[20];
printf("Please enter SID or name. Enter 0 to finish.\n");
scanf("%s",s);
if(strcmp(s,"0")==0)
break;
for(int i=0;i<Add_n;i++)
{
if(strcmp(My[i].SID,s)==0||strcmp(My[i].Name,s)==0)
{
printf("%d %s %d %s %d %d %d %d %d %.2lf\n",My[i].T,My[i].SID,My[i].CID,My[i].Name,My[i].S[0],My[i].S[1],My[i].S[2],My[i].S[3],My[i].Total,My[i].Average);
}
}
}
}
void ranking()
{
printf("Showing the ranklist hurts students' self-esteem. Don't do that.\n");
}
void Statistics()
{
int ID,t,n=0,pass[4]={0},K_pass[5]={0}; //四门通过人数,通过0,1,2,3,4科目数量的人数
double Average,Sum[4]={0}; //Sum【4】表示四门总分,
printf("Please enter class ID, 0 for the whole statistics.\n");
scanf("%d",&ID);
if(ID==0)
{
for(int i=0;i<Add_n;i++)
{
t=0;
for(int j=0;j<4;j++)
{
Sum[j]+=My[i].S[j]; //总分
if(My[i].S[j]>=60)
{
t++; //该生通过科目数量
pass[j]++; //该科通过的数量
}
}
K_pass[t]++;
}
n=Add_n;
}
else
{
for(int i=0;i<Add_n;i++)
{
if(My[i].CID==ID)
{
n++;
t=0;
for(int j=0;j<4;j++)
{
Sum[j]+=My[i].S[j]; //总分
if(My[i].S[j]>=60)
{
t++; //该生通过科目数量
pass[j]++; //该科通过的数量
}
}
K_pass[t]++;
}
}
}
int tn=n;
if(n==0)
n=1;
printf("Chinese\n");
printf("Average Score: %.2lf\n",1.0*Sum[0]/n+EPS);
printf("Number of passed students: %d\n",pass[0]);
printf("Number of failed students: %d\n\n",tn-pass[0]);
printf("Mathematics\n");
printf("Average Score: %.2lf\n",1.0*Sum[1]/n+EPS);
printf("Number of passed students: %d\n",pass[1]);
printf("Number of failed students: %d\n\n",tn-pass[1]);
printf("English\n");
printf("Average Score: %.2lf\n",1.0*Sum[2]/n+EPS);
printf("Number of passed students: %d\n",pass[2]);
printf("Number of failed students: %d\n\n",tn-pass[2]);
printf("Programming\n");
printf("Average Score: %.2lf\n",1.0*Sum[3]/n+EPS);
printf("Number of passed students: %d\n",pass[3]);
printf("Number of failed students: %d\n\n",tn-pass[3]);
printf("Overall:\n");
printf("Number of students who passed all subjects: %d\n",K_pass[4]);
printf("Number of students who passed 3 or more subjects: %d\n",K_pass[3]+K_pass[4]);
printf("Number of students who passed 2 or more subjects: %d\n",K_pass[2]+K_pass[3]+K_pass[4]);
printf("Number of students who passed 1 or more subjects: %d\n",K_pass[1]+K_pass[2]+K_pass[3]+K_pass[4]);
printf("Number of students who failed all subjects: %d\n\n",K_pass[0]);
}
int main()
{
// freopen("C:\\Users\\5201\\Desktop\\IN.txt","r",stdin);
// freopen("C:\\Users\\5201\\Desktop\\IOUT.txt","w",stdout);
while(1)
{
int n;
HAHA_printf();
scanf("%d",&n);
if(n==0) break;
else if(n==1) Add();
else if(n==2) Remove();
else if(n==3) Query();
else if(n==4) ranking();
else if(n==5) Statistics();
}
return 0;
}</span>
<span style="font-size:18px;">这是我至今写的最长的一份代码,得发发!</span>