平均最低最高等级计算机

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了平均最低最高等级计算机相关的知识,希望对你有一定的参考价值。

  1. #include <cstdlib>
  2. #include <iostream>
  3. #include "firstQuiz.h"
  4.  
  5. using namespace std;
  6.  
  7. static int studentNo = 1;
  8. static int zeroInput = 0;
  9.  
  10. firstQuiz::firstQuiz(int i)
  11. {
  12. errorC = i;
  13. }
  14.  
  15. void firstQuiz::errorHandling()
  16. {
  17. //static int errorC; //we can use this instead of interface solution
  18.  
  19. //if there is an error, show the error message
  20. if (errorC == 1)
  21. cout << "error: try again: ";
  22.  
  23. //no problem
  24. else
  25. cout << "enter the negative number tolerance quantity: ";
  26.  
  27. cin >> zeroInput;
  28.  
  29. if (zeroInput < 0)
  30. {
  31. errorC = 1; //error logger
  32. errorHandling(); //recursion
  33. }
  34. }
  35.  
  36. //if we don't want to write cout's again and again, we creat a function
  37. void firstQuiz::pointInput()
  38. {
  39. cout << "please enter the grade for student " << studentNo++ << " : ";
  40. cin >> point;
  41. }
  42.  
  43. //"everything is something happen" (sinyor terim)
  44. void firstQuiz::compute()
  45. {
  46. int zeroCount = 0;
  47. char closer;
  48. counterA = 0; avarageA = 0; maximumA = 0; minimumA = 100;
  49. counterB = 0; avarageB = 0; maximumB = 0; minimumB = 100;
  50.  
  51. //classic do-while structure
  52. do{
  53.  
  54. pointInput();
  55.  
  56. //when entered grade is negative and error handler is activated
  57. while(point<0 && zeroCount != zeroInput)
  58. {
  59. zeroCount++;
  60. cout << "negative! want to quit? (y / n) : ";
  61. cin >> closer;
  62. if (closer == 'y' || closer == 'Y')
  63. {
  64. break;
  65. }
  66. if( closer == 'n' || closer == 'N')
  67. {
  68. pointInput();
  69. }
  70. }
  71. //for above 50
  72. if(point>50)
  73. {
  74. counterA++;
  75. avarageA+=point;
  76. if(point > maximumA)
  77. maximumA=point;
  78. if(point < minimumA)
  79. minimumA=point;
  80. }
  81.  
  82. //for belove 50
  83. if(point<=50)
  84. {
  85. //if it is negative, easily ignore that!
  86. if(point<0)
  87. break;
  88. counterB++;
  89. avarageB+=point;
  90. if(point > maximumB)
  91. maximumB=point;
  92. if(point < minimumB)
  93. minimumB=point;
  94. }
  95.  
  96. }while(point>=0);
  97. }
  98.  
  99. //compute avarages seperately
  100. void firstQuiz::computeAvarage()
  101. {
  102. avarageA = avarageA / counterA; //for above 50
  103. avarageB = avarageB / counterB; //for belove 50
  104. }
  105.  
  106. //result outputs
  107. void firstQuiz::printResult()
  108. {
  109. //+50
  110. cout << endl << "maximum (+ 50) is " << maximumA << endl;
  111. cout << "minimum (+ 50) is " << minimumA << endl;
  112. cout << "avarage (+ 50) is " << avarageA << endl << endl;
  113. //-50
  114. cout << "maximum (- 50) is " << maximumB << endl;
  115. cout << "minimum (- 50) is " << minimumB << endl;
  116. cout << "avarage (- 50) is " << avarageB << endl << endl;
  117. }

以上是关于平均最低最高等级计算机的主要内容,如果未能解决你的问题,请参考以下文章

java基础 利用java计算一个同学成绩的最高最低平均分

如何在 TSQL 中排除 1800 万条记录的最高和最低 5% 的年薪,然后使用所选数据计算平均值

Cesium-如何计算点击位置周围指定区域的最高点、最低点、平均高度?

我如何找到这个学生数组中所有学生的最高、最低和总平均数

PHP计算显示平均温度五个最低及最高温度

每日一题:如何计算除去最高最低工资的部门平均工资