;; the structure represents a student ;; name is a symbol, ;; year-birth is a positive integer, ;; GPA is a non-negative real number <= 4.0 (define-struct ummstudent (name year-birth GPA)) ;; Template: ;;(ummstudent-name student) .... ;;(ummstudent-year-birth student) .... ;;(ummstudent-GPA student) .... (define JoeSmith (make-ummstudent 'JoeSmith 1990 3.45)) (ummstudent-name JoeSmith) (ummstudent-year-birth JoeSmith) (define JaneBrown (make-ummstudent 'JaneBrown 1991 3.25)) ;; Define test cases and fill in the body of the functions ;; Contract: ummstudent, ummstudent -> symbol ;; Purpose: the function compares the ages ;; of two students and returns the name of ;; the one who is older, based on the year of birth ;; If the two students were born in the same year, ;; the function returns a symbol 'BornSameYear (define (isOlder student1 student2) (cond [(= (ummstudent-year-birth student1) (ummstudent-year-birth student2)) 'BornSameYear] [(< (ummstudent-year-birth student1) (ummstudent-year-birth student2)) (ummstudent-name student1)] [else (ummstudent-name student2)] ) ) (check-expect (isOlder JoeSmith JaneBrown) 'JoeSmith) (check-expect (isOlder JaneBrown JoeSmith) 'JoeSmith) (check-expect (isOlder JoeSmith JoeSmith) 'BornSameYear) ;; Contract: ummstudent, ummstudent -> real ;; Purpose: the function retunrs the higher of the ;; GPAs for the two students ;(check-expect (max-GPA JaneBrown JoeSmith) 3.45) ;(check-expect (max-GPA JaneBrown JaneBrown) 3.25) ;; Contract: ummstudent, real -> ummstudent ;; Purpose: the function takes a ummstudent structure ;; and returns a new ummstudent structure with the same ;; student name and year of birth but with the new GPA ;; (define (update-GPA student new-GPA) (make-ummstudent (ummstudent-name student) (ummstudent-year-birth student) new-GPA ) ) (check-expect (ummstudent-GPA (update-GPA JoeSmith 3.5)) 3.5) (check-expect (ummstudent-name (update-GPA JoeSmith 3.5)) 'JoeSmith) (check-expect (ummstudent-GPA JoeSmith) 3.45) ;; Contract: ummstudent -> boolean ;; Purpose: to check whether a given "ummstudent" structure ;; is well-defined: the name is a symbol, the year ;; is an integer between 1900 and 2000, ;; the GPA is a number between 0 and 4.0 (define (is-valid student) (and (symbol? (ummstudent-name student)) ; check name (and (integer? (ummstudent-year-birth student)) ; check year-birth (<= (ummstudent-year-birth student) 2000) (>= (ummstudent-year-birth student) 1900)) (and (real? (ummstudent-GPA student)) ; check GPA (<= (ummstudent-GPA student) 4.0) (>= (ummstudent-GPA student) 0.0) ) ) ) (check-expect (is-valid JoeSmith) true) (check-expect (is-valid (make-ummstudent 5 'TheNineties -3.5)) false) (check-expect (is-valid (make-ummstudent 'JoeSmith 'TheNineties 3.5)) false) (check-expect (is-valid (make-ummstudent 'JoeSmith 1990 4.5)) false) (define eternal-student (make-ummstudent 'NoOneRemembersHisName 1960 1.95)) ;; age: ummstudent number -> number ;; age is a function that takes a perrson and current year ;; and returns the age of this person by the end of the year ;; add tests