a1q4 - 17)(make-meeting-time 'Sept 14 12)(make-meeting-time...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
;; 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-reader.ss" "lang")((modname a1q4) (read-case- sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) ;; CS 116 ;; r46wang Ru Wang 20319247 ;; Assignment 1 Question 4 (define-struct meeting-time (month day hr)) ;; count-afternoon: (listof meeting-time) -> num ;; counts the number of meetings there are in the list for which 12 <= (meeting- time hr) <= 17 ;; examples: ;;(count-afternoon (list (make-meeting-time 'Sept 10 0)(make-meeting-time 'Sept 10 11)(make-meeting-time 'Sept 10 18))) => 0 ;;(count-afternoon (list (make-meeting-time 'Sept 10 12)(make-meeting-time 'sept 10 15)(make-meeting-time 'Sept 10 17))) => 3 ;;(count-afternoon empty) => 0 ;;(count-afternoon (list (make-meeting-time 'Sept 16 8)(make-meeting-time 'Sept 17
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 17)(make-meeting-time 'Sept 14 12)(make-meeting-time 'Sept 24 14)(make-meeting-time 'Sept 20 19))) =&amp;gt; 3 ;; convert: meeting-time -&amp;gt; num ;; returns 1 if 12 &amp;lt;= (meeting-time hr) &amp;lt;= 17 and 0 otherwise. (define (count-afternoon meetings) (local [(define (convert n) (cond [(and (&amp;lt;= 12 (meeting-time-hr n))(&amp;lt;= (meeting-time-hr n) 17)) 1] [else 0]))] (foldr + 0 (map convert meetings)))) ;;tests: (check-expect (count-afternoon (list (make-meeting-time 'Sept 10 0)(make-meeting-time 'Sept 10 11)(make-meeting-time 'Sept 10 18))) 0) (check-expect (count-afternoon (list (make-meeting-time 'Sept 10 12)(make-meeting-time 'sept 10 15)(make-meeting-time 'Sept 10 17))) 3) (check-expect (count-afternoon empty) 0) (check-expect (count-afternoon (list (make-meeting-time 'Sept 16 8)(make-meeting-time 'Sept 17 17)(make-meeting-time 'Sept 14 12)(make-meeting-time 'Sept 24 14) (make-meeting-time 'Sept 20 19))) 3)...
View Full Document

This note was uploaded on 10/21/2010 for the course CS 116 taught by Professor T.vasiga during the Fall '09 term at Waterloo.

Ask a homework question - tutors are online