Guest User

Untitled

a guest
Apr 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. ;;Akhila Ankem
  2. ;; 12/02/11
  3. ;; Structure Notes 2
  4.  
  5. ;; A student is:
  6. ;; (make-student string string number string)
  7. (define-struct student (name grade teacher))
  8.  
  9. ;; CONTSRUCTOR
  10. ;; make-student: string string number string -> student
  11.  
  12. ;; SELECTOR
  13. ;; student-first: student -> string
  14. ;; student-last: student -> string
  15. ;; student-grade: student -> number
  16. ;; student-teacher: student -> string
  17.  
  18. ;; PREDICATE
  19. ;; student?: any -> boolean
  20.  
  21. (define EMILY (make-student "Emily" "Stevens" 3 "Dominguez"))
  22. (define MARIAH (make-student "Mariah" 1 "Wheeler"))
  23. (define WES (make-student "Wesley" 5 "Stone"))
  24.  
  25. ;; promote: student string-> student
  26. ;; Given a student and their new teacher, produces a student one grade higher
  27. (define (promote a-student)
  28. (make-student (student-first a-student)
  29. (student-last a-student)
  30. (+ 1 (student-grade a-student))
  31. new-teacher))
  32.  
  33. (check-expect (promote EMILY "Johnson")
  34. (make-student "Emily" "Stevens" 3 "Johnson"))
  35. (check-expect (promote SAMANTHA "Lightfoot")
  36. (make-student "Samantha" "Dearing" 3 "Lighthouse"))
  37. (check-expect (promote KYLE "Adams")
  38. (mame-student "Kyle" "Smith" 3 "Adams"))
  39.  
  40. ;; same-teacher?: student -> boolean
  41. ;; given two studnets, produces whether they have the same teacher.
  42. (define (same-teacher? a-student b-student)
  43. (string=? (student-teacher a-student) (student-teacher b-student)
  44. (student-first a-student)
  45. (student-last a-student)
  46. (student-grade a-student)
  47. (student-teacher a-student))
  48.  
  49. (check-expect (same-teacher? KYLE EMILY) false)
  50. (check-expect (same-teacher? SAMANTHA KYLE) false)
  51. (check-expect (same-teacher? kyle (make-student "Mary" "Jones" 1 "Hunt")) true)
Add Comment
Please, Sign In to add comment