a02sol - CS 135 Assignment 2 Solution Winter12 ;; 1]...

Info iconThis preview shows pages 1–5. 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
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 135 Assignment 2 Solution Winter12 ;; 1] cond.rkt ;; 8] [define [q 1a x] [cond [[and [131? x] [132? x]] 'One] [[131? x] 'Two] [[13 2? x] 'Three] [else 'Four]]] ;; 13] [define [q 1b x] [cond - [[or [131? x] [132? X]] 'One] \ ' \ [else 'Five]]] J: C] ( 2 [define [q 1c x] . ) [cond [[and [132? x] [133? x]] 'Three] [[13 2? x] 'Four] 2‘33 [else 'Five]]] \ I a ;; 2] sequence.rkt \1 I ;; sequence-type: Num Nut Num Num -> Sym ;; consumes four numbers, , b /c/, and d, and produces the symbol ’arithemetic ;; if the sequence a, b, c, d grithmetic, ’geometric ;; if the sequence a, b, c, d 's geometric, ’both if it is both, and ’neither if it is neither [check-expect [sequence-type 1 2 3 4] 'arithmetic] [check-expect [sequence-type 1 2 4 8] 'geometric] [check-expect [sequence-type 2 2 2 2] 'both] [check-expect [sequence-type 3 4 7 8] 'neither] [define [sequence-type a b c d] [cond [[= a b c (1] 'both] [[= [- b a] [- c b] [- d c]] 'arithmetic] [[and [not [= a 0]] [= b c d 0]] 'geometric] [[or [= a 0] [= b 0] [= c 0] [= d 0]] 'neither] [[= U 13 a] U C 13] U d CD 'geOmetriC] [else 'neither]]] This document is for the exclusive use of x8wen. [check-expect [sequence-type -2.5 0 2.5 5] 'arithmetic] [check-expect [sequence-type 10 0 -10 -20] 'arithmetic] [check-expect [sequence-type 0 0 0 0] 'both] [check-expect [sequence-type 2.3 2.3 2.3 2.3] 'both] [check-expect [sequence-type 3 0 0 0] 'geometric] [check-expect [sequence-type 10 5 2.5 1.25] 'geometric] [check-expect [sequence-type -1 2 -4 8] 'geometric] [check-expect [sequence-type 10 20 0 40] 'neither] ;; sequence-type: Num Num Num Num -> [union Num Bool] ;; consumes four numbers, a, b, c, and d, and produces the next number in the sequence ;; if the sequence a, b, c, d is arithmetic or geometric [or both], ; ; or false if the sequence is neither arithmetic nor geometri . [check-expect [sequence-next 0 0 0 0] 0] [check-expect [sequence-next 1 4 7 11] false] '-~. [define [sequence-next a b c d] [cond ( [[or x - [symbol=? [sequence-type a b c d] 'a'i‘ithme ic] [symbol=? [sequence-type a b c d] 'bo 1H d [- d c]]] [[symbol=? [sequence-type a'-- c dfgem etr c] [* d [/ b a]]] [else false D [check-expect [sequence-.1ext -1(2 it?) -16] [check-expect [sequence-1\ext 10 0.. 0 -20] -30] [check-expect [sequence-next 1K4 7 10] 13] [check-expect [sequence-n: xt 0 0 0] 0] ;; 3] grades.rkt ;; raw-grade : Int Int Int Int -> Num ;; Computes a student's raw CS 135 grade, given grades mt1 and mt2, final ; ; exam grade ex, and assignments grade assns, assuming perfect participation, ;; and ignoring requirements of passing assignments and exams. ;; Examples: [check-expect [raw-grade 0 0 0 100] 25] [check-expect [raw-grade 100 0 0 0] 15] [check-expect [raw-grade 0 100 0 0] 25] [check-expect [raw-grade 0 0 100 0] 50] [define mtlwt .1] [define mt2wt .2] [define exwt .45] This document is for the exclusive use of x8wen. [define assnwt .2] [define part 5] [define [raw-grade mt1 mt2 ex assns] [+ [* mt1 mt1wt] [* mt2 mt2wt] [* ex exwt] [* assns assnwt] part1] [check-expect [raw-grade 0 0 0 0] 5] [check-expect [raw-grade 100 100 100 100] 100] [check-expect [raw-grade 50 50 50 50] 52.5] ;; final-CSlBS-grade : Int Int Int Int -> Num _ ;; Computes the final CS 135 grade, given midterm grades. m 11d mt2, final ;; exam grade ex, and assignments grade assns, and assu' ing pe ect ;; participation. R ;; Examples: [check-expect [final-CSlBS-grade 100 100 00 60 100] [check-expect [final-CSlBS-grade 0 0 0 100 25] - [check-expect [final-CSlBS-grade 49 49433 1 0] 46)" [check-expect [final-CSlBS-grade 190 1%10 0] 46] H‘- [define fail-max 46] \ [define [final-CS 13 5-grad mtl Qua; assns] [cond i _. [[or [< assns 50] [< [/ [+ [* mt1 mtlwt', [* th mt2wt] [* ex exwtj] [+ mtlwt mt2wt e ]] 50]] [min [raw-grade mt1 mt2 ex assns] fail-max]] [else [raw-grade mt1 mt2 ex assns]]]] [check-expect [final-CSlBS-grade 0 0 0 0] 5] [check-expect [final-CSlBS-grade 50 50 50 100] 62.5] [check-expect [final-CSlBS-grade 100 100 100 50] 90] ;; clicker-marks : Int Int -> Num ; ; Determines the clicker grade, given the total questions answered, and the ; ; total questions answered correctly. ;; Examples: [check-expect [clicker-marks 60 30] 250/3] [check-expect [clicker-marks 60 60] 100] [check-expect [clicker-marks 30 0] 100 /3] This document is for the exclusive use of x8wen. [define num-questions 60] [define fi'action-that-count .75] [define questions-tllat-count [* num-questions fraction-tllat-count]] [define [clicker-marks answered correct] [/ [+ [* 2 [min correct questions-t11at-count]] [min [- answered correct] [max [- questions-tllat-count correct] 0]]] [* .02 questions-tllat-count]]] [check-expect [clicker-marks 0 0] 0] [check-expect [clicker-marks 45 45] 100] [check-expect [clicker-marks 60 45] 100] [check-expect [clicker-marks 45 44] 890/9] [check-expect [clicker-marks 44 44] 880/9] ;; 4] intervals.rkt \ \ ;; pitch->nat: Sym -> Nat ;; converts pitch name to natural number ( ;; Examples: - [check-expect [pitch->nat 'c] 0] [check-expect [pitch->nat 'b] 11] [define [pitch->natx] N . [cond [[symbol=? x 'c] 0] [[symbol=? x 'c#] 1] \ .. [[symbol=? x 'd] 2] [[symbol=? x 'd#] 3] / [[symbol=? x 'e] 4] ) [[symbol=?x 'f] 5] [[symbol=? x 'f#] 6] [[symbol=? x 'g] 7] [[symbol=? x 'g#] 8] [[symbol=? x 'a] 9] [[symbol=? x 'a#] 10] [[symbol=?x 'b] 11]]] ;;Tests: [check-expect [pitch->nat 'U 5] [check-expect [pitch->nat 'g#] 8] ;; nat->pitch: Sym -> Nat ; ; converts natural number to pitch name ;; Examples: [check-expect [nat->pitch 0] 'c] This document is for the exclusive use of x8wen. [check-expect [nat->pitch 11] 'b] [define [nat->pitch x] [cond [[= X 0] 'C] [[= X 1] 'C#] [[= X 2] 'd] [[= X 3] 'd#] [[= X4] '6] [[= X 5] '11 [[= X 6] 'f#] [[= X 7] 'g] [[= X 8] 'g#] [[= X9] '8] [[= x 10] 'a#] [(= x 11) 'bm \ . ;; Tests [check-expect [nat->pitch 3] 'd#] [check-expect [nat->pitch 9] 'a] ( 2 ;; transpose-interval: Sym Sym Sym -> Sym ;; consumes three notes pitchl, pitchZ aiidspitc 13 and returns the note pitch4 ;; such that pitchB-pitch4 denotes the san e Kind. of interval as pitchl—pitchZ [check-expect [transpose-intern? 'c 'Eifi-id 'd# [define [transpose-interval Site] -1 pit 112 pitc113] [nat->pitch [modulo [+ [Emitcfionat pitchZ] [pitch->nat pitc 1]] [pitch->nat pitch D 1?]] [check-expect [traiispose-ygterval 'c 'd 'e] 'f#] [check-expect [transpose-interval 'a# 'a# 'a#] 'a#] [check-expect [transpose-interval 'f 'f 'g] 'g] [check-expect [transpose-interval 'c# 'f 'a] 'c#] [check-expect [transpose-interval 'b 'c 'f#] 'g] [check-expect [transpose-interval 'd# 'g# 'f#] 'b] [check-expect [transpose-interval 'c 'c# 'b] 'c] [check-expect [transpose-interval 'a 'g# 'd#] 'd] [check-expect [transpose-interval 'c 'c# 'd#] 'e] [check-expect [transpose-interval 'c# 'c 'f#] 'U [check-expect [transpose-interval 'c 'c# 'g#] 'a] [check-expect [transpose-interval 'e 'f 'g] 'g#] This document is for the exclusive use of x8wen. ...
View Full Document

This note was uploaded on 04/02/2012 for the course CS 135 taught by Professor Vasiga during the Winter '07 term at Waterloo.

Page1 / 5

a02sol - CS 135 Assignment 2 Solution Winter12 ;; 1]...

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

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