Lab Module E -- Data Abstraction

CISC 280 Program Development Techniques

Purpose:
  1. To learn some basic concepts of data abstraction.
  2. To use and manipulate Scheme's basic data structure.
Goals:
  1. To write procedures that use data abstraction
  2. To be able to write procedures that use cons, car & cdr to access data elements.

Reading: SICP (Structure and Interpretation of Computer Programs), Section 2.1

Homework exercises (Due at start of lab 12 March 01):

  1. SICP Exercise 2.7

  2. SICP Exercise 2.10
    In this exercise, you can make use of Scheme's error function. The syntax is

    (error "Print some error message" irritant)

    where the irritant is whatever is causing the problem.
    Example:
    (define (divide-two-numbers x y)
        (cond ((= y 0) (error "Trying to divide by" y))
    	  (else (/ x y))))
    

    Now type this to the interpreter.
    (divide-two-numbers 3 0)
    Trying to divide by 0
    
    The error function will terminate the program if encounter. Also the irritant is optional, and when left out, error will just print out the error message and terminate the program.

    Notes:
    It is optional to use Scheme's error function.
    Make sure to hand in several test cases. In some of the test cases, the interval should span zero and in some it should not.

  3. SICP Exercise 2.12

    Flourishes (these are optional problems):

  4. SICP Exercise 2.1

  5. Make a function print-complex-numbers that prints complex numbers. You will have to make the selectors make-complex-number, real-part, and imag-part.
     
    (real-part (make-complex-number 1 3))
    1
    
    (imag-part (complex-number 3))
    3
    
    (print-complex-number (make-complex-number 1 3))
    1 + i3
    
    
    Remember complex numbers are in the form real-part + i imag-part.

  6. Make functions add-complex-numbers, subtract-complex-numbers, and multiply-complex-numbers that add, subtract, and multiply complex numbers.