Programming Assignment 1
C++ Requirements

Call your file arithmetic.cpp. Implement the following functions.

The following comments apply to all of them. All integers are stored in binary as arrays of bits, with the least significant bit stored at index 0. Array A has m bits. Array B has n bits.

Array R will hold the result when the function is finished. It is the caller's responsibility to ensure that array R has enough cells available to hold the answer. The number required is given for each function.

Variable Rsize is an out parameter that the functions sets to hold the number of bits that are actually in array R, not counting leading 0 bits, when the function is done. For example, if R contains 01101 (from high to low index), then its length is 4, since the leading 0 (in R[4]) is ignored. If all members of R are 0, then the length is 0. Rsize is strictly an out parameter. Its value on entry to the function must not be used.

  //=================================================================
  // inc(R,Rsize,A,m) stores one larger than the binary number in A into
  // array R.  That is, it computes R = A + 1 in binary.
  //
  // Array R must have at least m+1 cells available.
  //=================================================================

  void inc(BIT R[], int& Rsize, const BIT A[], int m);

  //=================================================================
  // sum(R,Rsize,A,m,B,n) stores the sum of integers A and B
  // into array R.  That is, it computes R = A + B.
  //
  // Array R must have at least max(m,n) + 1
  // cells available.  Those cells are set to hold the
  // binary sum of A and B
  //=================================================================

  void sum(BIT R[], int& Rsize, const BIT A[], int m, const BIT B[], int n);

  //=================================================================
  // product(R,Rsize,A,m,B,n) stores the product of integers A and B into
  // array R.  That is, it computes R = A * B.
  //
  // Array R must have at least m+n cells available.  Those
  // bits are set to the product of A and B.
  //=================================================================

  void product(BIT R[], int& Rsize, const BIT A[], int m, const BIT B[], int n);

For type BIT, use int. So you should write

  typedef int BIT;
in your file.