C语言编写一套学生成绩管理系统,可以计算学生平均分,各科平均分,按学生平均成绩排序,统计不合格学生信息。

叁歲伎倆 2022-04-13 06:42 329阅读 0赞

直接上代码

  1. #include <stdio.h>
  2. #include<stdlib.h>
  3. #define N 10 //假设有十个学生
  4. #define M 4
  5. void main()
  6. { int score[N][M];//定义一个二维数组,行表示学生号,列用来放三个科目第四列用来存放学生平均分
  7. char choice='1';
  8. void input(int a[][M],int,int);//函数声明
  9. void aver_stu(int score[][M],int,int);
  10. void aver_cour(int score[][M],int,int);
  11. void orde_aver(int score[][M],int,int);
  12. void failed(int score[][M],int,int);
  13. input(score,N,M);
  14. /*显示主菜单*/
  15. while(choice!='0')
  16. { system("cls");//清屏
  17. printf(" ==========the Score Processing System ====================\n");
  18. printf("1.print each student's average\n");
  19. printf("2.print each course's average\n");
  20. printf("3.Order the students by student's average decreasingly \n");
  21. printf("4.print the failed student \n");
  22. printf("0.Exit the system \n");
  23. printf("===============================================\n");
  24. printf("Please choise (0-4): \n");
  25. choice=getchar();
  26. switch(choice)
  27. {case '1':
  28. aver_stu(score,N,M); break;
  29. case '2':
  30. aver_cour(score,N,M); break;
  31. case '3':
  32. orde_aver(score,N,M); break;
  33. case '4':
  34. failed(score,N,M); break;
  35. case '0':
  36. exit(0);//退出系统
  37. default:
  38. printf("Choice Error,Please select again(0-4).");
  39. }
  40. }
  41. }
  42. void input(int score[][M],int,int)//学生成绩输入
  43. {
  44. int i,j;
  45. for(i=0;i<N;i++)
  46. { printf("输入第%d个学生的三门成绩",i+1);
  47. for(j=0;j<M-1;j++)
  48. scanf("%d",&score[i][j]);
  49. }
  50. system("pause");
  51. }
  52. void aver_stu(int score[][M],int,int)//求学生平均分
  53. {
  54. int i,j,ave;
  55. float s=0;
  56. for(i=0;i<N;i++)
  57. { s=0;
  58. for(j=0;j<M-1;j++)
  59. s+=score[i][j];
  60. ave=s/3;
  61. //a_stu[i]=s/3;
  62. printf("第%d个学生的平均分为%d\n",i+1,ave);
  63. }
  64. system("pause");
  65. }
  66. void aver_cour(int score[][M],int,int)//求三门课平均分
  67. {
  68. int i,j,ave;
  69. float s;
  70. for(j=0;j<M-1;j++)
  71. {s=0;
  72. for(i=0;i<N;i++)
  73. s+=score[i][j];
  74. ave=s/(float)N;
  75. printf(" 课程%d的平均分为%d\n",j+1,ave);
  76. }
  77. system("pause");
  78. }
  79. void orde_aver(int score[][M],int,int)//学生平均成绩降序排列
  80. {
  81. int i,j,t,y,a[20];
  82. float s=0;
  83. for(i=0;i<N;i++)
  84. a[i]=i+1;
  85. for(i=0;i<N;i++)
  86. { s=0;
  87. for(j=0;j<M-1;j++)
  88. s+=score[i][j];
  89. score[i][3]=s/3;
  90. }
  91. for(i=0;i<N-1;i++)
  92. for(j=0;j<N-j-1;j++)
  93. if(score[i][3]<score[i+1][3])
  94. { y=a[i];
  95. a[i]=a[i+1];
  96. a[i+1]=y;
  97. t=score[i][3];
  98. score[i][3]=score[i+1][3];
  99. score[i+1][3]=t;
  100. }
  101. printf("学生平均成绩降序排列\n");
  102. for(i=0;i<N;i++)
  103. printf("学生%d\t%d\n",a[i],score[i][3]);
  104. system("pause");
  105. }
  106. void failed(int score[][M],int,int)//统计不合格学生
  107. {
  108. int i,j;
  109. for(i=0;i<N;i++)
  110. for(j=0;j<M-1;j++)
  111. if(score[i][j]<60)
  112. printf("学生%d的课程%d成绩不合格\n",i+1,j+1);
  113. system("pause");
  114. }

在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,329人围观)

还没有评论,来说两句吧...

相关阅读