Advertisement
Guest User

lab6

a guest
Oct 23rd, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. const int PRECISION = 3;
  6.  
  7. // DO_04: Write the function prototype for GetThreshold
  8. // after completing DO_03.
  9.  
  10.  
  11. float GetThreshold( float & belowThreshold, float & aboveThreshold );
  12.  
  13. void displayResults( int count, float belowThreshold, int below,
  14. float aboveThreshold, int above );
  15.  
  16. void processOneNum( float num , float below_Threshold,
  17. float above_Threshold, int & count_below,
  18. int & count_above, int & totalCount );
  19.  
  20. int main()
  21. {
  22. float num, below_Threshold, above_Threshold;
  23. int totalCount = 0, belowCount = 0, aboveCount = 0;
  24.  
  25. // DO_05: Call the function GetThreshold to get
  26. // below_Threshold and above_Threshold.
  27. GetThreshold ( below_Threshold, above_Threshold );
  28.  
  29. cin >> num; // PRIMING READ
  30.  
  31. while ( !cin.eof() )
  32. {
  33. processOneNum ( num, below_Threshold, above_Threshold,
  34. belowCount, aboveCount, totalCount );
  35. cin >> num;
  36. }
  37.  
  38. displayResults( totalCount, below_Threshold, belowCount,
  39. above_Threshold, aboveCount );
  40. return 0;
  41. }
  42.  
  43. //-----------------------------------------------------------------------
  44. // This function updates three counters,
  45. // 1. total count of numbers
  46. // 2. how many numbers are larger than the above_Threshold, and
  47. // 3. how many numbers are smaller than the below_Threshold.
  48. // params: ( in, in, in, inout, inout, inout )
  49. //-----------------------------------------------------------------------
  50. void processOneNum( float num , float below_Threshold,
  51. float above_Threshold, int & count_below,
  52. int & count_above, int & totalCount )
  53. {
  54. // DO_02: Write the function body.
  55. // Remember that the belowThreshold is not neccesarily smaller
  56. // than the aboveThreshold
  57. if ( num < below_Threshold )
  58. {
  59. count_below ++;
  60. }
  61. else if ( num > above_Threshold )
  62. {
  63. count_above ++;
  64. }
  65. totalCount ++;
  66. }
  67.  
  68. //-----------------------------------------------------------------------
  69. // The function has two parameters of type float:
  70. // belowThreshold and aboveThreshold.
  71. // The function inputs two float values to belowThreshold and aboveThreshold
  72. // and pass them back to the calling function.
  73. // Parameters: (out, out)
  74. //-----------------------------------------------------------------------
  75. // DO_03: Complete the function header.
  76. float GetThreshold( float & belowThreshold, float & aboveThreshold )
  77. {
  78. cout << "Enter lower threshold: ";
  79. cin >> belowThreshold;
  80.  
  81. cout << "Enter upper threshold: ";
  82. cin >> aboveThreshold;
  83.  
  84. return belowThreshold, aboveThreshold;
  85. }
  86.  
  87. //-----------------------------------------------------------------------
  88. // This function outputs the final counts of: total
  89. // numbers, numbers above the aboveThreshold, and numbers
  90. // below the belowThreshold.
  91. // params: ( in, in, in, in, in )
  92. //-----------------------------------------------------------------------
  93. void displayResults( int count, float belowThreshold, int below,
  94. float aboveThreshold, int above )
  95. {
  96. cout << fixed << showpoint << setprecision(PRECISION);
  97.  
  98. cout << endl;
  99. cout << "Total count of numbers: " << count << endl;
  100. cout << "Below " << belowThreshold << ": " << below << endl;
  101. cout << "Above " << aboveThreshold << ": " << above << endl;
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement