C语言实现简易学生成绩管理系统

  #include

  #include

  #include

  //宏定义最大学生人数

  #define stu_max 30

  /*进行函数的全局声明*/

  //获取学生人数

  int stu_num();

  //显示菜单获取用户输入

  char menu_tips();

  //获取学生学号,及本门考试成绩

  void stu_information(long num[],float score[],int n);

  //计算输出课程的总分和平均分

  void sum_aver(float score[],int n);

  //模块功能:交换两个长整型数据

  void exchange_long(long *a,long *b);

  //模块功能:交换两个浮点型数据

  void exchange_float(float *a,float *b);

  //按成绩由高到低输出名次表

  void output_score(long num[],float score[],int n);

  //按学号从小到大排出成绩表

  void output_num(long num[],float score[],int n);

  //查询输出学生信息及考试成绩:

  void query(long num[],float score[],int n);

  //分数划界处理并输出

  void score_pro(float score[],int n);

  //直接输出对应列表

  void output(long num[],float score[],int n);

  //暂停清屏

  void clean();

  int main()

  {

  int n,i;

  long num[stu_max];

  float score[stu_max];

  n=stu_num();

  while(1)

  {

  i=menu_tips();

  switch(i)

  {

  case '1':printf("1"),stu_information(num,score,n),system("cls");break;

  case '2':printf("2"),sum_aver(score,n),clean();break;

  case '3':printf("3"),output_score(num,score,n),clean();break;

  case '4':printf("4"),output_num(num,score,n),clean();break;

  case '5':printf("5"),query(num,score,n),clean();break;

  case '6':printf("6"),score_pro(score,n),clean();break;

  case '7':printf("7"),output(num,score,n),clean();break;

  case '0':printf("0"),exit(0);break;

  default:printf("Input error!

  "),clean();

  }

  }

  }

  /*以下为函数功能模块*/

  //获取学生人数

  int stu_num()

  {

  int n;

  printf("Input student number(n<30):

  ");

  scanf("%d",&n);

  system("cls");

  return n;

  }

  //显示菜单获取用户输入

  char menu_tips()

  {

  printf(" -----------------------------------------------------------

  ");

  printf("| Management for Students' scores |

  ");

  printf(" -----------------------------------------------------------

  ");

  printf("| 1.Input record |

  ");

  printf("| 2.Calculate total and average score of course |

  ");

  printf("| 3.Sort in descending order by score |

  ");

  printf("| 4.Sort in ascending order by numbe |

  ");

  printf("| 5.Search by number |

  ");

  printf("| 6.Statistic analysis |

  ");

  printf("| 7.List record |

  ");

  printf("| 0.Exit |

  ");

  printf(" -----------------------------------------------------------

  ");

  printf("

  Please Input your choice:

  ");

  char i;

  i=getch();

  return i;

  }

  //获取学生学号,及本门考试成绩

  void stu_information(long num[],float score[],int n)

  {

  int i;

  printf("

  Input student's ID and score:

  ");

  for(i=0;i

  scanf("%ld%f",&num[i],&score[i]);

  }

  //计算输出课程的总分和平均分

  void sum_aver(float score[],int n)

  {

  int i;

  float sum,aver;

  for(i=0,sum=0;i

  sum+=score[i];

  aver=sum/n;

  printf("

  sum=%.0f,aver=%.2f

  ",sum,aver);

  }

  //模块功能:交换两个长整型数据

  void exchange_long(long *a,long *b)

  {

  long t;

  t=*a;

  *a=*b;

  *b=t;

  }

  //模块功能:交换两个浮点型数据

  void exchange_float(float *a,float *b)

  {

  float t;

  t=*a; *a=*b; *b=t;

  }

  //按成绩由高到低输出名次表

  void output_score(long num[],float score[],int n)

  {

  int i,j;

  for(j=n-1;j>0;j--)

  {

  for(i=0;i

  if(score[i]

  {

  exchange_float(&score[i],&score[i+1]);

  exchange_long(&num[i],&num[i+1]);

  }

  }

  printf("

  Sort in descending order by score:");

  output(num,score,n);

  }

  //按学号从小到大排出成绩表

  void output_num(long num[],float score[],int n)

  {

  int i,j;

  for(j=n-1;j>0;j--)

  {

  for(i=0;i

  if(num[i]>num[i+1])

  {

  exchange_float(&score[i],&score[i+1]);

  exchange_long(&num[i],&num[i+1]);

  }

  }

  output(num,score,n);

  }

  //查询输出学生信息及考试成绩:

  void query(long num[],float score[],int n)

  {

  printf("

  Enter the ID to query:

  ");

  long temp;

  scanf("%ld",&temp);

  int i;

  for(i=0;i

  {

  if(num[i]==temp)

  {

  printf("%ld %.0f

  ",num[i],score[i]);

  return;

  }

  }

  printf("

  Not found!

  ");

  }

  //分数划界处理并输出

  void score_pro(float score[],int n)

  {

  int t[6]={0,0,0,0,0,0};

  /*前五个分别对应优秀、良好、中等、及格、不及格五个类别

  第六位存储100分的人数*/

  int i,m;

  for(i=0;i

  {

  if(score[i]>=90&&score[i]<100) t[0]++;

  if(score[i]>=80&&score[i]<=89) t[1]++;

  if(score[i]>=70&&score[i]<=79) t[2]++;

  if(score[i]>=60&&score[i]<=69) t[3]++;

  if(score[i]>=0 &&score[i]<=59) t[4]++;

  if(score[i]==100) t[5]++;

  }

  //遍历t数组,输出对应的数据

  for(i=0,m=9;i<6;i++)

  {

  if(i==4)

  printf("<60 %d %.2f%%

  ",t[4],(float)t[4]/n*100);

  if(i==5)

  printf("%d %d %.2f%%

  ",100,t[5],(float)t[5]/n*100);

  if(i!=4&&i!=5)

  {

  if(i==0)

  printf("

  ");

  printf("%d-%d %d %.2f%%

  ",m*10,m*10+9,t[i],(float)t[i]/n*100);

  m--;

  }

  }

  }

  //直接输出对应列表

  void output(long num[],float score[],int n)

  {

  int i;

  for(i=0;i

  {

  if(i==0)

  printf("

  ");

  printf("%ld %.0f

  ",num[i],score[i]);

  }

  }

  //暂停清屏

  void clean()

  {

  system("pause");

  system("cls");

  }