Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;Akhila Ankem
- ;; 12/02/11
- ;; Structure Notes 2
- ;; A student is:
- ;; (make-student string string number string)
- (define-struct student (name grade teacher))
- ;; CONTSRUCTOR
- ;; make-student: string string number string -> student
- ;; SELECTOR
- ;; student-first: student -> string
- ;; student-last: student -> string
- ;; student-grade: student -> number
- ;; student-teacher: student -> string
- ;; PREDICATE
- ;; student?: any -> boolean
- (define EMILY (make-student "Emily" "Stevens" 3 "Dominguez"))
- (define MARIAH (make-student "Mariah" 1 "Wheeler"))
- (define WES (make-student "Wesley" 5 "Stone"))
- ;; promote: student string-> student
- ;; Given a student and their new teacher, produces a student one grade higher
- (define (promote a-student)
- (make-student (student-first a-student)
- (student-last a-student)
- (+ 1 (student-grade a-student))
- new-teacher))
- (check-expect (promote EMILY "Johnson")
- (make-student "Emily" "Stevens" 3 "Johnson"))
- (check-expect (promote SAMANTHA "Lightfoot")
- (make-student "Samantha" "Dearing" 3 "Lighthouse"))
- (check-expect (promote KYLE "Adams")
- (mame-student "Kyle" "Smith" 3 "Adams"))
- ;; same-teacher?: student -> boolean
- ;; given two studnets, produces whether they have the same teacher.
- (define (same-teacher? a-student b-student)
- (string=? (student-teacher a-student) (student-teacher b-student)
- (student-first a-student)
- (student-last a-student)
- (student-grade a-student)
- (student-teacher a-student))
- (check-expect (same-teacher? KYLE EMILY) false)
- (check-expect (same-teacher? SAMANTHA KYLE) false)
- (check-expect (same-teacher? kyle (make-student "Mary" "Jones" 1 "Hunt")) true)
Add Comment
Please, Sign In to add comment