P3: Counts for Numbers

Assignment for CS2390 Sp'96, Due 5/28

The Story

If you had a special kind of integer count (from Chapter 1 of Coad & Nicola) which only held a single digit (0-9), then one could imagine connecting these single digit integer counts in a series to create multiple digit counters. Incrementing the series would be the same as incrementing the least significant digit counter, but when it incremented past 9 to 0, it should tell the next most significant digit counter to increment.

There's nothing in this scheme which requires that the multiple digit counters represent only base 10 numbers. The least significant digit counter could just as soon increment its neighbor on the increment from 1 to 0 (binary numbers) or from 7 to 0 (base 8).

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.

The Assignment

In C++, implement multiple digit counters, including the ability to add and subtract one counter from another. I want to be able to run the below main function with your 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:

Discussion space for P3