CPSC 110 Lecture 11: CPSC 110
CPSC 110 verified notes
11/26View all
Document Summary
In this problem imagine you have information about a bunch of people that you would like to store as data and present in different ways. ;; constants: (define font-size 24) (define font-colour "blue") ;; data definitions: (@htdd person) (define-struct person (name age)) [else ( (fn-for-person (first lop)) (fn-for-lop (rest lop)))])) ;; functions: (@htdf arrange-people) (@signature listofperson -> image) ;(define (arrange-people lop) empty-image) ;stub (@template fn-composition) (define (arrange-people lop) (layout-people (sort-people lop))) (@htdf layout-people) (@signature listofperson -> image) ;(define (layout-people lop) empty-image) ;stub (@template listofperson) (define (layout-people lop) (cond [(empty? lop) empty-image] [else (above (render-person (first lop)) (layout-people (rest lop)))])) (@htdf render-person) (@signature person -> image) ;; produce an image of a person (check-expect (render-person p1) (text "wendy: 14" font-size font-colour)) (check-expect (render-person p3) (text (string-append (person-name p3) (number->string (person-age p3))) ;(define (render-person p) empty-image) ;stub (@template person) (define (render-person p) (text (string-append (person-name p) ": " (number->string (person-age p)))