set 7 - ;Assighnment 6 ;Kyo-Dong Ryo ;1085 ; ;...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
;;Assighnment 6 ;;Kyo-Dong Ryo ;;1085 ;; ;; (define-struct child (father mother name date eyes)) ;; Child = (make-child FTN FTN String Number Symbol) ;; A family-tree-node (short: FTN) is either ;; -empty ;; -Child ;; Test Children ;; Oldest Generation: (define Carl (make-child empty empty 'Carl 1926 'green)) (define Bettina (make-child empty empty 'Bettina 1926 'green)) ;; Middle Generation: (define Adam (make-child Carl Bettina 'Adam 1950 'yellow)) (define Dave (make-child Carl Bettina 'Dave 1955 'black)) (define Eva (make-child Carl Bettina 'Eva 1965 'blue)) (define Fred (make-child empty empty 'Fred 1966 'pink)) ;; Youngest Generation: (define Gustav (make-child Fred Eva 'Gustav 1988 'brown)) ;; Examples: ;; (equal? (average-age Carl 2006) 80) ;; (equal? (average-age Eva 2006) 67) ;; average-age: FTN Number -> Number ;; To find the average age of members in a family tree from the current year. (define (average-age ch yr) (/ (branch-age ch yr) (count-persons ch))) ;; branch-age: FTN Number -> Number ;; To find the combined age of all members in a FTN. (define (branch-age ch yr) (cond [(empty? ch) 0] [(and (empty? (child-father ch)) (empty? (child-mother ch))) (age ch yr)] [(empty? (child-father ch)) (+ (age ch yr) (branch-age (child-mother ch) yr))] [(empty? (child-mother ch)) (+ (age ch yr) (branch-age (child-father ch) yr))] [else (+ (branch-age (child-father ch) yr) (branch-age (child-mother ch) yr)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
(age ch yr))])) ;; age: Child Number -> Number ;; To determine the age of a child. (define (age ch yr) (- yr (child-date ch))) ;; count-persons: FTN -> Number ;; To count the number of persons in a FTN. (define (count-persons ch) (cond [(empty? ch) 0] [(and (empty? (child-father ch)) (empty? (child-mother ch))) 1] [(empty? (child-father ch)) (add1 (count-persons (child-mother ch)))] [(empty? (child-mother ch)) (add1 (count-persons (child-father ch)))] [else (+ (count-persons (child-father ch))
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/26/2008 for the course CS 211 taught by Professor Matthias.f during the Fall '07 term at Northeastern.

Page1 / 6

set 7 - ;Assighnment 6 ;Kyo-Dong Ryo ;1085 ; ;...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online