;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname applying_functions) (read-case-sensitive #t) (teachpacks ((lib "testing.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "testing.ss" "teachpack" "htdp"))))) ;; 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 to accomplish the following tasks: ;; create a list of students names (in any order) ;; create a list of students whose GPA is 3.0 or above ;; find the average GPA of all students ;; create a list of only valid student structures of the ones given ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; use quicksort function to sort the student list by age ;; Can we use isOlder for this? How or why not? ;; 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 ;; longer exercise: find the standard deviation of the GPAs as defined here: ;; http://en.wikipedia.org/wiki/Standard_deviation#Discrete_random_variable_or_data_set