For the Upper Bounded Counter class there should be: private integer field named
ID: 3778230 • Letter: F
Question
For the Upper Bounded Counter class there should be: private integer field named counter. private integer field named max. public default constructor that assigns 0 to counter and 10 to max. public overload constructor that takes an integer parameter. It assigns the parameter to max and assigns 0 to counter. public get accessor method for all field. Decrement () decrements counter by 1. Increment () increments counter by 1 if counter is less than max. At Limit () returns true if counter equals max. Info () returns a string with the following format [-INF; ; ]. Reset () assigns 0 to counter.Explanation / Answer
#include <iostream>
#include <string.h>
using namespace std;
class UpperBoundedCounter{
private:
int counter;
int max;
public:
UpperBoundedCounter(){
counter = 0;
max = 10;
}
UpperBoundedCounter(int max){
this->max = max;
counter = 0;
}
int getCounter(){
return counter;
}
int getMax(){
return max;
}
void Decrement(){
counter--;
}
void Increment(){
counter++;
}
bool AtLimit(){
if(counter == max) return true;
return false;
}
string Info(){
return string("[-INF ; ") + to_string(counter) + " ; " + to_string(max) + string(" ]");
}
void Reset(){
counter = 0;
}
};
int main(){
}