第十三周项目六(2)英语成绩统计

- 日理万妓 2022-08-14 02:51 233阅读 0赞
  1. 问题及代码:
  2. /*
  3. *Copyright (c) 2014,烟台大学计算机学院
  4. *ALL right reserved
  5. *文件名;seventyeight.cpp
  6. *作者;童宇
  7. *完成日期2014年11月23日
  8. *版本号v1.0
  9. *问题描述:英语成绩处理
  10. *输入描述:
  11. *程序输出:
  12. */
  13. #include <iostream>
  14. #include <cmath>
  15. using namespace std;
  16. double ave;
  17. void input_score(int s[], int n);
  18. int get_max_score(int s[], int n);
  19. int get_min_score(int s[], int n);
  20. double get_avg_score(int s[], int n);
  21. int count(int x, int s[], int n); //返回在数组s中n名同学中有多少人得x分(实参给出最高/低时,可以求最高/低成绩的人数)
  22. int good (int s[], int n);
  23. int bad (int s[], int n);
  24. void output_index(int x, int s[], int n); //在函数中输出数组s中n名同学中得x分的学号(下标)
  25. int main(void)
  26. {
  27. int score[50]; //将score设为局部变量,通过数组名作函数参数,传递数组首地址,在函数中操作数组
  28. int num;//小组人数也设为局部变量,将作为函数的实际参数
  29. int max_score,min_score;
  30. cout<<"小组共有多少名同学?";
  31. cin>>num;
  32. cout<<endl<<"请输入学生成绩:"<<endl;
  33. input_score(score, num);
  34. max_score=get_max_score(score, num);
  35. cout<<endl<<"最高成绩为:"<<max_score<<",共有 "<<count(max_score, score, num )<<" 人。";
  36. min_score=get_min_score(score, num);
  37. cout<<endl<<"最低成绩为:"<<min_score<<",共有 "<<count(min_score,score, num )<<" 人。";
  38. cout<<endl<<"平均成绩为:"<<get_avg_score(score, num);
  39. ave=get_avg_score(score, num);
  40. cout<<endl<<"获最高成绩的学生(学号)有:";
  41. output_index(max_score,score, num);
  42. cout<<endl<<"获最低成绩的学生(学号)有:";
  43. output_index(min_score,score, num);
  44. cout<<"\n获得优秀的有人数为:"<< good (score, num)<<"\n不及格的人数为:"<< bad (score, num);
  45. cout<<endl;
  46. return 0;
  47. }
  48. void input_score(int s[], int n)
  49. {
  50. int i,c;
  51. for(i=0; i<n; i++)
  52. {
  53. cin>>c;
  54. if(c>=0&&c<=100)
  55. {
  56. s[i]=c;
  57. }
  58. else
  59. cout<<"请正确输入成绩!";
  60. }
  61. }
  62. int get_max_score(int s[], int n)
  63. {
  64. int max=0,i;
  65. for(i=0; i<n; i++)
  66. {
  67. if(max<s[i])
  68. max=s[i];
  69. }
  70. return max;
  71. }
  72. int get_min_score(int s[], int n)
  73. {
  74. int min=100,i;
  75. for(i=0; i<n; i++)
  76. {
  77. if(min>s[i])
  78. min=s[i];
  79. }
  80. return min;
  81. }
  82. double get_avg_score(int s[], int n)
  83. {
  84. int i,sum=0,ave;
  85. for(i=0; i<n; i++)
  86. {
  87. sum=sum+s[i];
  88. }
  89. ave=sum/n;
  90. return ave;
  91. }
  92. int count(int x, int s[], int n)
  93. {
  94. int i,j=0;
  95. for(i=0; i<n; i++)
  96. {
  97. if(s[i]==x)
  98. j++;
  99. }
  100. return j;
  101. }
  102. void output_index(int x, int s[], int n)
  103. {
  104. int i;
  105. for(i=0; i<n; i++)
  106. {
  107. if(x==s[i])
  108. cout<<i<<" ";
  109. }
  110. }
  111. int good (int s[], int n)
  112. {
  113. int i,j=0;
  114. for(i=0; i<n; i++)
  115. {
  116. if(s[i]>=85)
  117. j++;
  118. }
  119. return j;
  120. }
  121. int bad (int s[], int n)
  122. {
  123. int i,j=0;
  124. for(i=0; i<n; i++)
  125. {
  126. if(s[i]<60)
  127. j++;
  128. }
  129. return j;
  130. }

运行结果:

Center

发表评论

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

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

相关阅读