;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname LectureSept15) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #t))) ;; a ListOfNumber is one of ;; empty ;; (cons Number ListOFNumber) ;; extract-positives: ListOfNumber -> List)fNumber ;; (define (extract-positives alon) (cond [(empty? alon) empty ] [(cons? alon) (if (>= (first alon) 0) (cons (first alon) (extract-positives (rest alon))) (extract-positives (rest alon)))])) (check-expect (extract-positives empty) empty) (check-expect (extract-positives (cons -5 (cons -3 empty))) empty) (check-expect (extract-positives (cons 7 (cons 2 empty))) (cons 7 (cons 2 empty))) (check-expect (extract-positives (cons -3 (cons 3 (cons 0 (cons -5 empty))))) (cons 3 (cons 0 empty))) (define-struct course (dept coursenum term sections seats)) ;; a Course is a (make-course String Natural String Natural Natural) ;; interp: a course where ;; dept is the department ;; coursenum is the course number ;; term is the term the course is offered ;; sections is the number of sections ;; seats is the number of seats per section ;; examples (define MA2201 (make-course "MA" 2201 "A" 8 30)) (define CS1101 (make-course "CS" 1101 "C" 6 25)) ;;; fcn-for-course: Course -> ;;; ;(define (fcn-for-course a-course) ; (course-dept a-course) ; (course-coursenum a-course) ; (course-term a-course) ; (course-sections a-course) ; (course-seats a-course)) ;; a ListOfCourse is one of ;; empty ;; (cons Course ListOfCourse) ;; examples (define SCHED (cons MA2201 (cons CS1101 empty))) ;;; fcn-for-loc: ListOfCourse -> ;;; ;(define (fcn-for-loc aloc) ; (cond [(empty? aloc) ] ; [(cons? aloc) (...(fcn-for-course (first aloc)) ; (fcn-for-loc (rest aloc)))])) ;; course-capacity: ListOfCourse -> Natural ;; produces the total number of seats in all sections in all courses in the list (define (course-capacity aloc) (cond [(empty? aloc) 0 ] [(cons? aloc) (+ (capacity-of-one (first aloc)) (course-capacity (rest aloc)))])) ;; capacity-of-one: Course -> Natural ;; produces the number of all seats in all sections of the course (define (capacity-of-one a-course) (* (course-sections a-course) (course-seats a-course))) (check-expect (capacity-of-one MA2201) 240) (check-expect (course-capacity empty) 0) (check-expect (course-capacity SCHED) 390)