a02sol - ;; Assignment 2, Question 1 ;; Question 1a (define...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ;; Assignment 2, Question 1 ;; Question 1a (define (qla x) (cond [(and (p1? x) (p2? x)) (f1 x)] [(Pl? x) (f2 x)] [(PZ? x) (f3 x)] [(P3? x) (f4 x)] [else (£5 x)])) ;; Question 1(b) (define (qlb x) (cond [(and (number? x) (> x 5)) (f1 x)] [(number? x) (f3 x)] [(Pl? x) (f4 x)] [else (£5 x)])) ;; Question lc (define (qlc x) (cond [(and (pl? 3:) (p2? x)) (£1 15)] [(and (not (p1? xn (p3? 2:) (p4? xn GIN [(ps'? 2:) (f2 m . / [else (£3 x)])) _ ;; Assignment 2, Question 2 ;; Question 1(a) ;; some useful constants (define midlweight 0.1) (define mid2weight 0.2) (define finalweight 0.45) (define assignweight 0.2) (define partweight 0.05) (define max—weight—exam—score (* 100 (+ midlweight mid2weight finalweight))) (define failing—max 46) ;; final—csl35—grade: Nat Nat Nat Nat Nat —> Num ;,' Purpose: ;; compute the final grade that a student would get in C8135 ;; given the assignment grade (out of 100, weight of 20%), ;; midterm 1 (out of 100, weight of 10%), ;; midterm 2 (out of 100, weight of 20%) ;; final exam (out of 100, weight of 45%) ;; participation grade (out of 100, weight of 45%) ;,' Examples: (check—expect (final—cslSS—grade 49 100 100 100 100) 46) This document is for the exclusive use of j65lu. (define (final—cs135—grade assign midl mid2 final part) (cond [(or (< assign 50) (< (+ (* midl midlweight) (* mid2 mid2weight) (* final finalweight)) (/ max—weight—exam—score 2))) (min failing—max (+ (* midl midlweight) (* mid2 mid2weight) (* final finalweight) (* part partweight) (* assign assignweight)))] [else (+ (* midl midlweight) (* mid2 mid2weight) (* final finalweight) (* part partweight) (* assign assignweight))])) ;; Test for final—cs135—grade (check—expect (final—cs135—grade D D 0 D 0) 0) (check—expect (final—cs135—grade 50 50 50 50 50) 50) (check—expect (final—cs135—grade 50 49 50 50 50) 46) (check—expect (final—cs135—grade 50 50 49 50 50) 46) (check—expect (final—cs135—grade 50 50 50 49 50) 46) (check—expect (final—cs135—grade 60 60 60 60 60) 60) (check—expect (final—cs135—grade 12 13 14 15 16) 14.05) ;; Question 1(b) ;; an important constant \\\\ (define num—questions 52) _ /} (define fraction—that—count 0.75) _, (define questions—that—count (* num—ques ions frac ion—that—count)) ;; participation—mark: Nat Nat —> Ndm ,Jiu ,, Purpose: (( _/ ;; compute the participation L rk \aéga n er between 0 and 100) ;; given the number of correc:fa r incorrect answers, ;; assuming there were 52 clicker quest-ons asked in the course ;; note that only the top 75% of the questions are counted ; ; Examples : (check—expect (participation—mark 39 ') 100) (check—expect (participation—mark 38 1) (* 100 (/ (+ (* 38 2) 1) (* 39 2)))) (define (participation—mark correct incorrect) (/ (+ (* 2 (min correct questions—that—count)) (min incorrect (max (— questions—that—count correct) 0))) (* 0.02 questions—that—count))) ;; Tests (check—expect (participation—mark 0 0) 0) (check—expect (participation—mark 39 39) 100) (check—expect (participation—mark 25 5) (* 100 (/ (+ (* 25 2) 5) (* 39 2)))) This document is for the exclusive use of j65lu. ;; can—donate ;; Purpose: I I ; ; Examples : —to/oond?: Symbol Symbol —> Boolean To determine whether the donor‘s blood type ;; is compatible with the recipienth blood type. (check—expect (oan—donate—to/oond? ‘0— ‘0—) true) (check—expect (oan—donate—to/oond? ‘O+ ‘A—) false) (define (oan—donate—to/oond? donor reoip) (oond [(symbol=? [(symbol=? [(symbol=? [(symbol=? [(symbol=? [(symbol=? [else (check—expect (check—expect (check—expect (check—expect (check—expect (check—expect (check—expect (check—expect (check—expect (check—expect (check—expect donor reoip donor donor donor false])) (oan—donate—to/oond? ‘0— ‘ (oan—donate—to/oond? :¢+ (oan—donate—to/oond’ ‘O+‘ (oan—donate—to Lend? (oan—donate—to/ooi (oan—donate—to/oond; (oan—donate—to/oond? (oan—donate—to/oond? (oan—donate—to/oond? (oan—donate—to/oond? (oan—donate—to/oond? donor reoip) true] '0—) true] 'AB+) true] '0+) (oond [(symbol=? reoip [(symbol=? reoip [else false])] 'A—) (oond [(symbol=? reoip [(symbol=? reoip [else false])] 'B—) (oond [(symbol=? reoip [(symbol—? re 'p [else fals\])] ‘A+) true] ‘B+) true] ‘A+) true] ‘AB—) true] ‘ +) true] ‘AB true] _'/ tru ) ;tests 2 ‘ ) tr e) ;tests 3 +)-t e) ;tests 4 ‘6: ‘B\) true) ;tests 5 d? ‘ “A ) true) ;tests 7 'A-v’ —) true) ;tests 8 ‘0+) false) ;tests 9 ‘B+) true) ;tests 10 ' ‘AB—) true) ;tests 11 ‘B— ‘0+) false) ;tests 12 ‘B+ ‘0+) false) ;tests 13 ‘1. a. a. u“. ‘1- ‘1- ODaJO‘iLfl-hbJMI—l u“. ;tests 1 ;tests 6 This document is for the exclusive use of j65lu. ;; can—donate—to/bool?: ;; Purpose: Symbol Symbol ;; can be donated to the recipient I I ; ; Examples : —> Boolean To determine whether the donor‘s blood type (check—expect (oan—donate—to/bool? ‘0— ‘0—) true) (check—expect (oan—donate—to/bool? ‘O+ ‘A—) false) (define (oan—donate—to/bool? donor reoip) (or (symbol=? donor reoip) (symbol=? donor '0—) (symbol=? reoip 'AB+) (and (symbol=? donor ‘0+) (or (symbol=? reoip 'A+) (symbol=? reoip 'B+))) (and (symbol=? donor ‘A—) (or (symbol=? reoip 'A+) (symbol=? reoip 'AB-))) (and (symbol=? donor ‘B—) (or (symbol=? reoip 'B+) )) ;; Tests (check—expect (check—expect (check—expect (check—expect (check—expect (check—expect (check—expect (check—expect (check—expect (check—expect (check—expect (symbol=? reoip 'AB-))) (oan—donate—to/bool? :0— (oan—donate—to/bool? jfi+ (oan—donate—to/bool' ‘O+‘ (oan—donate—to fool? (oan—donate—to/"otl? (oan—donate—to/bool; (oan—donate—to/bool? (oan—donate—to/bool? (oan—donate—to/bool? (oan—donate—to/bool? ‘B— (oan—donate—to/bool? 'Q lA_ :5 (6 if false) :8 (9 if false) ;10 ‘ tru ) ‘ 5) tr e) - ) ‘B\) true) “A ) true) ‘ —) true) ‘O+) false) ‘B+) true) ‘AB—) true) ‘O+) false) ‘O+) false) 1: ‘+ m ;11\q\2;£ IL lse) :.3 if _ e) ntire or is false ;tests ;tests ;tests ;tests ;tests ;tests ;tests ;tests ;tests ;tests ;tests ODnJLfl-lhwk) ‘0 ll 12 13 ;tests 1 ;tests 6 This document is for the exclusive use of j65lu. ...
View Full Document

This note was uploaded on 01/18/2012 for the course CS 135 taught by Professor Vasiga during the Fall '07 term at Waterloo.

Page1 / 4

a02sol - ;; Assignment 2, Question 1 ;; Question 1a (define...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online