Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Gauge is a type of counter that specifies a positive value up to a certain gauge

ID: 3836247 • Letter: G

Question

Gauge is a type of counter that specifies a positive value up to a certain gauge maximum. Gauge is always positive. More specifically, gauge belongs to the range between 0 and some MAX value, inclusive. Thus, your class Gauge must have two data members: gauge_value max_value The primary operations that you need to perform on the gauge are Default constructor: Set gauge_value to 0, and max_value to MAX integer value (see page 392 for details) Class constructor: set gauge_value and max_value values. Increment: increase gauge value by user-specified value. Decrement: decrease gauge value by user-specified value. Set: set gauge value with argument to function. Set_MAX: set the value of gauge max with argument to function. Get: return gauge_value. Get MAX: return max_value.

Explanation / Answer

#include <iostream>
#include <limits.h>
using namespace std;
class Gauge
{
    int gauge_value;
    int max_value;
    public:
        Gauge()
        {
           gauge_value = 0;
           max_value = INT_MAX;
        }
        Gauge(int gVal, int mVal)
        {
           if(gVal >= mVal)
           {
              gauge_value = 0;
               max_value = INT_MAX;
               cout << "gauge_value must be less than max_value." << endl;
           }
           else
           {
              gauge_value = gVal;
              max_value = mVal;
           }
        }
        void increment(int val)
        {
           if(gauge_value + val > max_value)
               cout << "gauge_value cannot be assigned beyond max_value." << endl;
           else
               gauge_value += val;  
        }
        void decrement(int val)
        {
           if(gauge_value - val < 0)
               cout << "gauge_value cannot be less than 0." << endl;
           else
               gauge_value -= val;  
        }
        void set(int val)
        {
           if(val > 0 && val <= max_value)
               gauge_value = val;
           else
               cout << "Invalid value entered...." << endl;  
        }
        void set_max(int max)
        {
           if(max > gauge_value)
               max_value = max;
           else
               cout << "max should be greater than max_value" << endl;  
        }
        int get()
        {
           return gauge_value;
        }
        int get_max()
        {
           return max_value;
        }
};