Get Tech'Ed HomePage

Course Homepage


CSM CSCI-400

Racket Homework #01

(Last Mod: 17 December 2013 13:16:53 )


Purpose:

This homework is to be done individually. For simplicity, put all three parts in the same file.

Document your code well. If the grader has difficulty following your reasoning, they will take away from the 25% allocated toward Effort.


Preparation:


Part I: Process a list recursively. 10 points.

Write a function named containsAnywhere

Use the unitTest below to verify your function is correct.

(define (unitTest)
  (and 
   (containsAnywhere 'a '(a))
   (containsAnywhere 'a '(b a))
   (not (containsAnywhere 'a '(c d)))
   (containsAnywhere 'a '((a) b))
   (containsAnywhere 'b '((c d e) (g b e)))
   (containsAnywhere 'b '((c d e) (g (b) e)))
   (not (containsAnywhere 'x '((c d e) (g (b) e))))
   (containsAnywhere 'f '((c d e) (g (b) e) f))
   (not (containsAnywhere 'h '((c d e) (g (b) e) f)))
   ))

Part II: Modify a list recursively. 10 points.

Write a function named removeAll that takes an item to be removed and a list and returns the list with all instances of that item removed.

Use the unitTest below to verify your function is correct.

(define (unitTest2)
  (and 
   (equal? (removeAll 'a '(b a c)) '(b c))
   (equal? (removeAll 'a '((b a c d))) '((b c d)))
   (equal? (removeAll 'b '((b a c d (f)))) '((a c d (f))))
   (equal? (removeAll 'b '((b a c d (f b)))) '((a c d (f))))
   (equal? (removeAll 'b '((b a c d (f (b))))) '((a c d (f ()))))
   (equal? (removeAll 'b '((b a c d (f (b g))))) '((a c d (f (g)))))
   ))

Part III: First class procedures. 20 points.

In this homework assignment you will be creating a small conversion "calculator" that will allow you to easily define and call conversion functions. The image below shows two executions of the calculator, one converting feet to meters, one converting a temperature from fahrenheit to celcius.

Calculator execution 

Specific requirements:

Hints:

Submission:

Put all of your solutions into a single file.

Name your program CS400_UserID_R_01.rkt (as usual, UserID is replaced with YOUR CSM User ID)

Submit your .rkt file on Blackboard.