Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- const int PRECISION = 3;
- // DO_04: Write the function prototype for GetThreshold
- // after completing DO_03.
- float GetThreshold( float & belowThreshold, float & aboveThreshold );
- void displayResults( int count, float belowThreshold, int below,
- float aboveThreshold, int above );
- void processOneNum( float num , float below_Threshold,
- float above_Threshold, int & count_below,
- int & count_above, int & totalCount );
- int main()
- {
- float num, below_Threshold, above_Threshold;
- int totalCount = 0, belowCount = 0, aboveCount = 0;
- // DO_05: Call the function GetThreshold to get
- // below_Threshold and above_Threshold.
- GetThreshold ( below_Threshold, above_Threshold );
- cin >> num; // PRIMING READ
- while ( !cin.eof() )
- {
- processOneNum ( num, below_Threshold, above_Threshold,
- belowCount, aboveCount, totalCount );
- cin >> num;
- }
- displayResults( totalCount, below_Threshold, belowCount,
- above_Threshold, aboveCount );
- return 0;
- }
- //-----------------------------------------------------------------------
- // This function updates three counters,
- // 1. total count of numbers
- // 2. how many numbers are larger than the above_Threshold, and
- // 3. how many numbers are smaller than the below_Threshold.
- // params: ( in, in, in, inout, inout, inout )
- //-----------------------------------------------------------------------
- void processOneNum( float num , float below_Threshold,
- float above_Threshold, int & count_below,
- int & count_above, int & totalCount )
- {
- // DO_02: Write the function body.
- // Remember that the belowThreshold is not neccesarily smaller
- // than the aboveThreshold
- if ( num < below_Threshold )
- {
- count_below ++;
- }
- else if ( num > above_Threshold )
- {
- count_above ++;
- }
- totalCount ++;
- }
- //-----------------------------------------------------------------------
- // The function has two parameters of type float:
- // belowThreshold and aboveThreshold.
- // The function inputs two float values to belowThreshold and aboveThreshold
- // and pass them back to the calling function.
- // Parameters: (out, out)
- //-----------------------------------------------------------------------
- // DO_03: Complete the function header.
- float GetThreshold( float & belowThreshold, float & aboveThreshold )
- {
- cout << "Enter lower threshold: ";
- cin >> belowThreshold;
- cout << "Enter upper threshold: ";
- cin >> aboveThreshold;
- return belowThreshold, aboveThreshold;
- }
- //-----------------------------------------------------------------------
- // This function outputs the final counts of: total
- // numbers, numbers above the aboveThreshold, and numbers
- // below the belowThreshold.
- // params: ( in, in, in, in, in )
- //-----------------------------------------------------------------------
- void displayResults( int count, float belowThreshold, int below,
- float aboveThreshold, int above )
- {
- cout << fixed << showpoint << setprecision(PRECISION);
- cout << endl;
- cout << "Total count of numbers: " << count << endl;
- cout << "Below " << belowThreshold << ": " << below << endl;
- cout << "Above " << aboveThreshold << ": " << above << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement