Create a special kind of integer count which holds a single digit in a
given base (2 - 37), and which can be connected together with other
special integer counts in a series, to create multiple digit counters.
Incrementing the series would be the same as incrementing the least
significant digit of the counter, but when the least significant digit
is incremented past it's base minus one, it should tell the next most
significant digit counter to increment.
Once we have several multiple digit counters, we can do arithmetic with
them. Series A minus series B means that we decrement A for as many times as
we have to decrement B to reach 0 on all of B's counters. Adding B to A means
that we increment A for as many counts as in B.
This problem involves implementing multiple digit counters in
C++, including the ability to add and subtract one counter
from another. We must be able to run the below main function with our
program.
#include
#include "multiple.h"
int main()
{
// Create a multiple count object in base 10 with four digits
Multiple_Count first(10,4);
// Create a multiple count object in base 2 with 8 digits,
// initialized to 15.
Multiple_Count second(2,8,15);
int i;
cout << endl << "MULTIPLE DIGIT COUNTER DEMO" << endl;
cout << endl << "Second value" << second.value() << endl;
first.setvalue(5); // Load 5 into first
for (i=0; i < 123 ; i++)
first.increment(); // Add in 123
cout << endl << "First value" << first.value() << endl;
first.subtract(second); // Subtract second from first
cout << endl << "First - second " << first.value() << endl;
second.add(second);
cout << endl << "Second + second " << second.value() << endl;
}
Some additional points:
- Multiple_Count
value should return a string, so as to preserve the representation of the series in the given base.
- We should deal with overflow (i.e., addition that goes beyond the capacity of the Multiple_Count series) with an appropriate error message to
cout
- We are expected to reuse Integer_Count in this example.
- We must not assume an upper limit on the number of digits a
Multiple_Count may have.
- We should allow for the base of a Multiple_Count to range from 2 to 37
(0 - 9 A-Z).
- We do not need to deal with a user interface for this problem.