Mom's Counter

READ ME (Chapter 10, 11)

MCounter:

Here are the public member functions of the MCounter class:

class MCounter
{
public:
    MCounter();
    int add_1();                //increment functions
    int add_10();
    int add_100();
    int add_1000();
    int reset();                //reset error  state, _count
    int count() const;          //returns _count
    bool error() const;         //returns _error
    bool is_error() const;      //true  if an error has occurred

private:
    int add(int n);             //add n to _count
    int _count;
    bool _error;
};

Testing:

Write a function called test_MCounter() and call it from main()

In test_MCounter:

Display to the user, the following menu and allow the user to make a choice:

[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it

As the user presses A, S, D, F increment the count by appropriate values. 

at the bottom of the loop, before you read the next command, display the count by calling a function called display_count and pass it the MCounter object. The display function checks to see if the object is in an error state. If it is, it will display ERROR otherwise, it will show the current count.

Once the object goes into the error state, no valid count exists until the user calls reset()

Please see Class design guidelines for a list of do's and don'ts.

 

Here is sample output:

 

-------
| 0000|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it f
-------
| 0001|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it f
-------
| 0002|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it f
-------
| 0003|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it d
-------
| 0013|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it d
-------
| 0023|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it s
-------
| 0123|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it s
-------
| 0223|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it a
-------
| 1223|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it a
-------
| 2223|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it a
-------
| 3223|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it a
-------
| 4223|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it a
-------
| 5223|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it a
-------
| 6223|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it a
-------
| 7223|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it a
-------
| 8223|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it a
-------
| 9223|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it a
-------
|ERROR|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it f
-------
|ERROR|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it d
-------
|ERROR|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it a
-------
|ERROR|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it r
-------
| 0000|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it s
-------
| 0100|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it s
-------
| 0200|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it f
-------
| 0201|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it f
-------
| 0202|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it f
-------
| 0203|
-------
[A] 1000  [S] 100   [D] 10   [F] 1    [R]eset:   e[X]it x


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