// Please be aware of Academic Honesty Policy // DO NOT MODIFY THIS FILE // Your code should work with this code unmodified. // ASSIGN1: Due Friday July 18th Midnight. Instruction for // submitting will be provided later. // Late submissions will not be accepted. // Please note. It is your responsibility to turn the program ahead of time. // No late submissions will be accepted. // Please remember to following the recommended coding standard // and commenting style. // In this assignment, you will develop an abstraction of a // ModuloCounter. A ModuloCounter represents a counter that // counts in a cyclic form. For example, a ModuloCounter with // a mod limit of 5 will count only in the range 1 to 5. If the // value of the counter is 1, a call to an ncrement function will // take the value to 2. Repeated calls to increment will // take the value from 2 to 3, 3 to 4, 4 to 5 and then from 5 to // 1 again since it will not exceed the mod limit. // When constructing a ModCounter object, the user is required to // specify the mod limit for that counter object. // The user may call a function increment to increase the counter's // value by one. However, the count will rollback to 1 if the // counter's value is at its limit when increment is called. // The user may call a function decrement to decrease the counter's // value by one. However, the count will roll to the limit value if the // counter's value is 1 when decrement is called. // The user may call getCounterValue() to obtain the current value of the // counter. // The user may call getCounterLimit() to obtain the mod limit value. // The user may call getNumberofModuloCounters() to find out how many objects // of the mod counter exists. #include #include "ModuloCounter.h" void printCounterInfo(const ModuloCounter& theCounter); // prints the Value of the Counter void printCounterValueAndCount_1(const ModuloCounter theCounter); // prints the Value of the Counter and the Number of Counters // Takes a ModuloCounter object by Value void printCounterValueAndCount_2(const ModuloCounter& theCounter); // prints the Value of the Counter and the Number of Counters // Takes a ModuloCounter object by Reference // The objective of above functions is to see the effect of // taking an argument object by value and by reference void main() { ModuloCounter counter(3); // Mod limit for this counter is 3 printCounterInfo(counter); counter.increment(); printCounterInfo(counter); counter.increment(); printCounterInfo(counter); counter.increment(); printCounterInfo(counter); counter.decrement(); printCounterInfo(counter); cout << "Number of Counters while in main: " << ModuloCounter::getNumberofModuloCounters() << endl; { // Starts a new scope here ModuloCounter anotherCounter(4); // Mod limit for this counter is 4 cout << "Number of Counters while in inner scope: " << anotherCounter.getNumberofModuloCounters() << endl; } // End of the inner scope... // the object anotherCounter is destroyed cout << "Number of Counters while in main: " << ModuloCounter::getNumberofModuloCounters() << endl; printCounterValueAndCount_1(counter); cout << "Number of Counters while in main: " << ModuloCounter::getNumberofModuloCounters() << endl; printCounterValueAndCount_2(counter); cout << "Number of Counters while in main: " << ModuloCounter::getNumberofModuloCounters() << endl; int limit = 0; counter.getCounterLimit(limit); cout << "The limit on the counter is: " << limit << endl; } void printCounterInfo(const ModuloCounter& theCounter) // prints the Value of the Counter { cout << "Counter Value is " << theCounter.getCounterValue() << endl; } void printCounterValueAndCount_1(const ModuloCounter theCounter) // prints the Value of the Counter and the Number of Counters // Takes a ModuloCounter object by Value { cout << "Counter Value is " << theCounter.getCounterValue() << endl; cout << "Number of Counters while in printCounterValueAndCount_1: " << ModuloCounter::getNumberofModuloCounters() << endl; } void printCounterValueAndCount_2(const ModuloCounter& theCounter) // prints the Value of the Counter and the Number of Counters // Takes a ModuloCounter object by Reference { cout << "Counter Value is " << theCounter.getCounterValue() << endl; cout << "Number of Counters while in printCounterValueAndCount_2: " << ModuloCounter::getNumberofModuloCounters() << endl; }