ENG 101 Final: University of British Columbia CPSC 110 Lab 5

5 views12 pages

Document Summary

;; cpsc 110 - helpers lab (require spd/tags) (require 2htdp/image) (require 2htdp/universe) (@assignment lab-05) (@cwl ???) ;; complete the design of a function called pyramid that takes a natural. ;; number n and an image, and constructs an n-tall, n-wide pyramid of. ;; for instance, a 3-wide pyramid of cookies would look like this: ;; interp. a natural number (define n0 0) ;0 (define n1 (add1 n0)) ;1 (define n2 (add1 n1)) ;2 (@dd-template-rules one-of atomic-distinct compound self-ref) (define (fn-for-natural n) (cond [(zero? n) ()] [else ( n ; n is added because it"s often useful (fn-for-natural (sub1 n)))])) ;; functions (@problem 1) (@htdf pyramid) (@signature natural image -> image) ;; produce an n-tall, n-wide pyramid of the given image (check-expect (pyramid 0 cookies) empty-image) (check-expect (pyramid 1 square) square) (check-expect (pyramid 3 cookies) (above cookies (beside cookies cookies) (beside cookies cookies cookies))) ;(define (pyramid n i) empty-image) ; stub (@template natural) (define (pyramid n i) (cond [(zero? n) empty-image]

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers