PSICS Fall 2004 - HW#3

HW#3: Function Templates


This assignment involves developing scheme code templates for various kinds of functions. For each template you must provide:

Below is an example template for "arithmetic functions of a single variable":




Template: Arithmetic functions of a single variable

This template describes scheme funcitons that use arithmetic operations to compute to compute some mathematical function f(x) given a value of x. This template can be used in situations where the f is continuous (discrete functions generally would require something different, probably involving a cond statement).

The functions that match this template consume a number and produce a number.

General structure of the function definition:

(define (func x)
  ...some mathematical operations on x ...
)

Example 1: celcius-to-fahrenheit

;;
;; function celcius-to-fahrenheit number => number
;;
;; (celcius-to-fahrenheit c) computes the temperature in
;;   degrees fahrenheit that correspond to the temperature c in
;;   celcius. The formula used is:
;;
;;  fahrenheit = 32 + (celcius * 9/5)
;;
;; sample usage: (celcius-to-fahrenheit 100)

(define (celcius-to-fahrenheit c)
  (+ 32 (* c 9/5)))

;;
;; test code
;;
(celcius-to-fahrenheit 0)  ;; should produce 32
(celcius-to-fahrenheit -40)  ;; should produce -40
(celcius-to-fahrenheit 100)  ;; should produce 212

Example 2: cube

;;
;; function cube number => number
;;
;; (cube x) calculates x raised to the 3rd power
;;
;; sample usage: (cube 2)

(define (cube x)
  (* x (* x x)))


;;
;; test code
;;
(cube 2) ;; should produce 8
(cude 1) ;; should produce 1
(cube -2) ;; should produce -8

Templates you need to develop

You need to develop each of the templates described below. For each description below, make sure that your template is not an over-simplifications - it should address all functions that could be described by the statement.

Submission

Submit your functions by 11:59 PM, Monday, Oct 11th by submitting to the WebCT dropbox labeled "HW3".