Counter_Type

READ ME (Chapter 10, 11)

Design the class using the specifications in the textbook.

CounterType will have the following declarations:

 

class Counter_Type
{
public:
    Counter_Type();
    Counter_Type(int n);            //set initial value of the counter
    bool inc();                     //increment by one
    bool dec();                     //decrement by one
    bool is_error() const;          //true: the object is in error (underflow)
    bool reset();                   //reset _count to zero and _error to false
    int count() const;              //retrieve the _count
private:
    int _count;
    bool _error;
};

 

The dec() function will set the _error to true if the count is zero upon being called.

 

Testing:

Your main() function calls the test_CounterType() function.

test_Counter_Type() presents the user with the following menu:

[+]  [-]     [R]eset:  e[X]it  

as the user presses + and -, you will call the appropriate functions from the CounterType object and call the display_counter() function and pass it the CounterType object. 

The display_counter() object will display the count if the object is not in error. Otherwise, it will display ERROR.

Sample Run:

 

-------
| 0000|
-------
[+]  [-]     [R]eset:  e[X]it  +
-------
| 0001|
-------
[+]  [-]     [R]eset:  e[X]it  +
-------
| 0002|
-------
[+]  [-]     [R]eset:  e[X]it  +
-------
| 0003|
-------
[+]  [-]     [R]eset:  e[X]it  +
-------
| 0004|
-------
[+]  [-]     [R]eset:  e[X]it  +
-------
| 0005|
-------
[+]  [-]     [R]eset:  e[X]it  +
-------
| 0006|
-------
[+]  [-]     [R]eset:  e[X]it  +
-------
| 0007|
-------
[+]  [-]     [R]eset:  e[X]it  +
-------
| 0008|
-------
[+]  [-]     [R]eset:  e[X]it  +
-------
| 0009|
-------
[+]  [-]     [R]eset:  e[X]it  +
-------
| 0010|
-------
[+]  [-]     [R]eset:  e[X]it  +
-------
| 0011|
-------
[+]  [-]     [R]eset:  e[X]it  -
-------
| 0010|
-------
[+]  [-]     [R]eset:  e[X]it  -
-------
| 0009|
-------
[+]  [-]     [R]eset:  e[X]it  -
-------
| 0008|
-------
[+]  [-]     [R]eset:  e[X]it  -
-------
| 0007|
-------
[+]  [-]     [R]eset:  e[X]it  -
-------
| 0006|
-------
[+]  [-]     [R]eset:  e[X]it  -
-------
| 0005|
-------
[+]  [-]     [R]eset:  e[X]it  -
-------
| 0004|
-------
[+]  [-]     [R]eset:  e[X]it  -
-------
| 0003|
-------
[+]  [-]     [R]eset:  e[X]it  -
-------
| 0002|
-------
[+]  [-]     [R]eset:  e[X]it  -
-------
| 0001|
-------
[+]  [-]     [R]eset:  e[X]it  -
-------
| 0000|
-------
[+]  [-]     [R]eset:  e[X]it  -
-------
|ERROR|
-------
[+]  [-]     [R]eset:  e[X]it  -
-------
|ERROR|
-------
[+]  [-]     [R]eset:  e[X]it  -
-------
|ERROR|
-------
[+]  [-]     [R]eset:  e[X]it  +
-------
|ERROR|
-------
[+]  [-]     [R]eset:  e[X]it  +
-------
|ERROR|
-------
[+]  [-]     [R]eset:  e[X]it  r
-------
| 0000|
-------
[+]  [-]     [R]eset:  e[X]it  +
-------
| 0001|
-------
[+]  [-]     [R]eset:  e[X]it  +
-------
| 0002|
-------
[+]  [-]     [R]eset:  e[X]it  x

-------------------
Press <RETURN> to close this window...