Project 1: Arithmetic Tutor

CMSC 330, Sections 0201/0202

written by Michael L. Scott, edited by Vibha Sazawal

Note:If you choose to work with a project partner, you must choose someone that is in your section.

You are building an arithmetic tutor to help elementary-school children learn longhand multiplication and division. As part of the tutor, you need two functions, lmult and ldiv, that output answers to arithmetic questions in longhand.

  1. Write a Scheme function lmult, to display the longhand multiplication of two nonnegative integers. For example, if you type
         > (lmult 1234 567)
     
    you should see the output
      1234
       567
    ------
      8638
     74040
    617000
    ------
    699678
     
    Similarly, if you type
         > (lmult 567 1234)
     
    you should see
       567
      1234
    ------
      2268
     17010
    113400
    567000
    ------
    699678
     
    The output of your lmult function should look EXACTLY like the format shown above. It should work for arbitrarily large numbers.
  2. Write a Scheme function ldiv to display the longhand division of two nonnegative integers. Instead of computing a terminating or repeating decimal, print out a remainder. For example, if you type
         > (ldiv 573 45)
     
    you should see the output
          12R33
        ----
    45 | 573
         45
         ---
         123
          90
         ---
          33
     
    As another example, if you type
        > (ldiv 24 2)
    
    you should see the output
        12 
       ---
    2 | 24
        2 
        --
         4
         4
         -
         0
    
    Do not write R0 if the remainder is zero. Also, attempted division by zero should result in an error message.
       > (ldiv 402 2)
    
    outputs
        201
       ----
    2 | 402
        4
        --
         0
         0
         --
          2
          2
          -
          0
    
    > (ldiv 2 402)
    
    outputs
          0R2
         --
    402 | 2
          0
          -
          2  
    
    > (ldiv 4861 12)
    
    outputs
          405R1
        -----
    12 | 4861
         48
         ---
           6
           0
           --
           61
           60
           --
            1
    

IMPORTANT NOTES: PLEASE READ

Deadlines