Assignment #4 - 86B

Assignment #4 - 86B


                      Assignment #4
                      Due: Oct. 21, 1986      T.A. Bernard Chung
                   Weight: 25


 This  assignment  is  an extension  of  assignment  #3.   In
 addition to  the ability to  add two 20-digit  numbers, your
 program must be able to subtract two such numbers.

 Write a  program to read in  a character ('+', '-'  or '$'),
 and two 20-digit numbers into 20-location  C H A R A C T E R
 arrays,  from three  consecutive input  lines.  Convert  the
 character arrays into  20-digit numbers and store  them into
 20-location INTEGER  arrays.  Then, perform  the appropriate
 operation according to the character read in, as follows:
      '+' : Add the two 20-digit numbers.
      '-' : Subtract the SMALLER of the two numbers
            from the other one.

 Repeat for all the input lines,  until the character read in
 is '$', and the two numbers read in are all zeros.

 You  may   assume  that   all  the   20-digit  numbers   are
 non-negative.  However, you have to  check for any errors in
 the input.  Also, be sure to check for possible overflow, in
 the case of addition.


 You have to write the following subprograms:

 CONVRT: To convert a 20-location CHARACTER array into a
         20-digit number stored in a 20-location INTEGER
         array.

 ADD   : To add two 20-digit numbers stored in INTEGER
         arrays, and store the sum into another
         20-location INTEGER array.

 SUB   : To subtract a 20-digit number from another one
         (both stored in 20-location INTEGER arrays), and
         store the result into another 20-location INTEGER
         array.


 The input is found in the file INF8:ASS4.DATA
 Example of input:

 -
 12345678901234567890
  9876543210987654321
 +
 12345678901234567890
 54321098765432109876
 -
 54321098765432109876
 56789012345678901234
 -
 12345678901234567890
 1234567ERROR34567890
 +
 98765432109876543210
 12345678901234567890
 #
 12345678901234567890
 12345678901234567890
 $
 00000000000000000000
 00000000000000000000


 Your output should look like this:

 12345678901234567890 -
  9876543210987654321
 --------------------
  2469135690246913569
 --------------------

 **********************

 12345678901234567890 +
 54321098765432109876
 --------------------
 66666777666666677766
 --------------------

 **********************

 56789012345678901234 -
 54321098765432109876
 --------------------
  2467913580246791358
 --------------------

 **********************

 12345678901234567890 -
 1234567ERROR34567890
 --------------------
 ERROR IN OPERAND
 --------------------

 **********************

 98765432109876543210 +
 12345678901234567890
 --------------------
 OVERFLOW
 --------------------

 **********************

 12345678901234567890 #
 12345678901234567890
 --------------------
 ERROR IN OPERATION
 --------------------

 **********************