|
|
||
|
|
Start of topic | Skip to actions
How to do your homework
;; COMP 210 HW #01 ;; Christopher Warrington <chrisw@rice.edu> ;; Gregory Malecha <gmalecha@rice.edu> Submitting your homework For submission instructions, please see the SVN Turnin tutorial. Basic form of a function definition: (Chapter 2 onwards)
;; area-of-ring : positive-real-number positive-real-number -> positive-real-number
;; to compute the area of a ring whose radius is
;; outer and whose hole has a radius of inner
;;
;; Examples:
;; (area-of-ring 5 3) => 50.24
;; (area-of-ring 5 0) => 78.5
;;
(define (area-of-ring outer inner)
(- (area-of-disk outer)
(area-of-disk inner)))
"Testing area-of-ring:" ;; This line helps your grader
(equal? (area-of-ring 5 3) 50.24)
(equal? (area-of-ring 5 0) 78.5)
... ;; Provide enough examples and tests to show you tested thoroughly
Data Definitions and Templates: (Chapter 6 onwards) Once data definitions are introduced in class, you will be required to include them in your homework submissions. You need to think (and document) your design for data definitions before you start writing functions that process data of this type. Data definitions should be documented as follows:
;; A shape is either
;; * a triangle (make-triangle b h),
;; where b and h are positive-reals
;; * a square (make-square s),
;; where s is a positive-real.
(define-struct triangle (base height))
(define-struct square (side))
;;
;; Examples:
;; (make-triangle 1 2)
;; (make-triangle 2 5)
;; (make-square 4)
;; (make-square 2.5)
;;
;; Template:
#|
;; shape-function : shape -> ...
(define (shape-function ... shape ...)
(cond [(triangle? shape) ... (triangle-base shape) ...
... (triangle-height shape) ...]
[(square? shape) ... (square-side shape) ...]))
|#
;; A list-of-numbers is either
;; empty, or
;; (cons n lon)
;; where n is a number, and lon is a list-of-numbers
;;
;; Examples:
;; empty
;; (cons 1 empty)
;; (cons 1 (cons 4 empty))
;;
;; Template:
#|
;; f : list-of-numbers -> ...
(define (f a-lon)
(cond
[(empty? a-lon) ...]
[(cons? a-lon) ... (first a-lon) ...
... (f (rest a-lon)) ... ]))
|#
Termination Argument: (Chapter 23 onwards) If the template does not guarantee that a function terminates, you are required to explain why that function will terminate for all possible inputs.
;; quick-sort [real] -> [real]
;; Sorts the given list in ascending order.
;;
;; Examples:
;; (quick-sort empty) => empty
;; (quick-sort '(1)) => '(1)
;; (quick-sort '(1 4 3 5)) => '(1 3 4 5)
;; (quick-sort '(1 4 3 4 2 5)) => '(1 2 3 4 4 5)
;;
;; Termination:
;; At each step, quick-sort partitions the list into three
;; sublists using smaller-than, larger-than, and equal-to.
;; The lists produced by smaller-than and larger-than are
;; sorted using recursive applications. Since the lists
;; produced by smaller-than and larger-than are strictly
;; shorter than the given list, eventually quick-sort
;; receives and returns the empty list.
(define (quick-sort alon)
(cond
[(empty? alon) empty]
[else (append (quick-sort (smaller-items alon (first alon)))
(equal-to alon (first alon))
(quick-sort (larger-items alon (first alon))))]))
"Testing quick-sort:"
...
Access Permissions
Topic Actions: Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r57 < r56 < r55 < r54 < r53 | More topic actions
Webs: Main | TWiki | Africa | EmbeddedSystems | Gpce | Houston | International | K12 | MetaOCaml | MulticoreOCR | ProgrammingLanguages | RAP | RIDL | Sandbox | SpeechClub | Teaching | Texbot | WG211 Web Actions: |
|
This work is licensed under a Creative Commons Attribution 2.5 License. Please follow our citation guidelines.