;; 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)) ;; 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 -> 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 (ummstudent? student) (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 students (list JoeSmith JaneBrown (make-ummstudent 'MichaelAnderson 1990 2.95) (make-ummstudent 'KristinJones 1992 3.73))) ;; use predefined functions filter, map, foldl/foldr to accomplish ;; the following tasks: ;; create a list of students names (in any order) (map ummstudent-name students) ;; GPA-over-3? ummstudent -> boolean (define (GPA-over-3? a-student) (>= (ummstudent-GPA a-student) 3.0) ) ;; create a list of students whose GPA is 3.0 or above (filter GPA-over-3? students) ;; find the average GPA of all students (/ (foldr + 0 (map ummstudent-GPA students)) (length students)) ;; create a list of only valid student structures of the ones given (filter is-valid (cons (make-ummstudent 2 3 4) students)) (quicksort (list 2 4 7 3 1 3 5) <) ;; use quicksort function to sort the student list by age ;; Can we use isOlder for this? How or why not? ;; is-younger? ummstudent, ummstudent -> boolean (define (is-younger? student1 student2) (< (ummstudent-year-birth student1) (ummstudent-year-birth student2)) ) (quicksort students is-younger?) ;; using any of the given functions, write a function that finds if any ;; of the students have GPA below 2.0. This function returns true if there ;; is at least one such student and false otherwise ;; using any of the functions, find out how many students have GPA ;; 3.0 or above