Design Recipe Three - Compound Data

DATA ANALYSIS AND DESIGN
- Determine pieces of data that describe properties and essential elements of the object
CONTRACT, PURPOSE, HEADER - Name of program, Input / Output
EXAMPLES - Function Calls (2 or more) with the estimated answer that YOU calculate.
TEMPLATE - SELECTOR Expressions for parameters that stand for compound values
BODY - If program is conditional, complete branch template first
TEST - Execute the program. Compare the computer answer to your estimate. Check logic.


SUBSTITUTE TEACHER - SECTION 5.4

DATA ANALYSIS AND DESIGN
- Determine pieces of data that describe properties and essential elements of the object
STRUCTURE DEFINITION
   (define-struct student (first last teacher))
DATA DEFINITION
   ;; A student is a structure:
   ;;    (make-student f l t)
   ;;    where f, l, and t are symbols.
EXAMPLES using the selectors and constructor
   (student-first (make-student 'Juan 'Johnson 'North)) = 'Juan
   (student-last (make-student 'Mukaila 'Pham 'Hebert)) = 'Pham
   (student-teacher (make-student 'Jeff 'Brown 'North)) = 'North
CONTRACT, PURPOSE, HEADER - Name of program, Input / Output
;;subst-teacher: student symbol -> student
;;Create a student structure with a new substitute teacher 
    if the teacher's name is Mrs. North
(define (subst-teacher learner substitute)
EXAMPLES - Function Calls (2 or more) with the estimated answer that YOU calculate.
(subst-teacher (make-student 'Juan 'Johnson 'North) 'Stromstead) = 
                                  (make-student 'Juan 'Johnson 'Stromstead)
(subst-teacher (make-student 'Mukaila 'Pham 'Hebert)'Stromstead) = 
                                  (make-student 'Mukaila 'Pham 'Hebert)
TEMPLATE - SELECTOR Expressions for parameters that stand for compound values
(define (subst-teacher learner substitute)
 (cond
  [..(student-teacher learner)..
   ..(student-first learner)  ..
   ..(student-last learner)   ..]
  [                             ])
BODY - If program is conditional, complete branch template first
(cond
 [(eq? (student-teacher learner) 'North) 
    (make-student(student-first learner)(student-last learner)substitute)]
 [else learner]))
TEST - Execute the program. Check logic.
(define-struct student (first last teacher))
;; A student is a structure:
;;    (make-student f l t)
;;    where f, l, and t are symbols.
(student-first (make-student 'Juan 'Johnson 'North)) = 'Juan
(student-last (make-student 'Mukaila 'Pham 'Hebert)) = 'Pham
(student-teacher (make-student 'Jeff 'Brown 'North)) = 'North

;;subst-teacher: student symbol -> student
;;Create a student structure with a new substitute teacher if the teacher is Mrs. North
(define (subst-teacher learner substitute)
  (cond
    [(eq? (student-teacher learner) 'North) (make-student
                                             (student-first learner)
                                             (student-last learner)
                                             substitute)]
    [else learner]))
  
(subst-teacher (make-student 'Juan 'Johnson 'North) 'Stromstead) = 
                            (make-student 'Juan 'Johnson 'Stromstead)
(subst-teacher (make-student 'Mukaila 'Pham 'Hebert)'Stromstead) = 
                            (make-student 'Mukaila 'Pham 'Hebert)