You are on page 1of 7
reteocours: (Dietof any) -> Nat pais let ts nonempty: produced value > ¢ f tines the first elenen ft oceurs an lat iexarpless (first-occure (lier (first-occure (list fa fs count the nunber of items equal to length (filter equal-first? 1st)})) “expect (first-oceurs (List ‘a)) 1) vee eee ee \, 6 1 ae ot Length 2 fet ones once oa ay DY makcomenct (etratomune (List teabeosm 2 2) oh Boa LEE ae cae a a acim egy Kottom ek ouemrs ane meaning SMe ul: check exper a Dow wy aoa amy (mm-nonalpha los) los} (define all-chars (string-list (foldr string-append subtract ters from the total nunber unber of alpha chai ¢ charact length all-chara} length (filter char-alphabetic? all-chars) a ry) 0) le lists of Length 1 - containing no, some, and all nonalpha characters -nenalpha (list "abo"!) 9) (list "abei2")) 2 alpha (list "La#ss7e8Q")) 10: This document is for the exclusive use of hapatel. longer ists = containing no, some, and all nonalpha characters (check-expect (ntm-nonalpha (List "a" "sl Mahe Nemanaplanacenalpanaa")) 0) (check-expect (nim-nonalpha (Liat Man" "abem 2245" Mo ")) 16) (check-expect (ntm-nenalpha (Liat "om ee) =e am) 38) (Aetine-struct cara (anit valve!) Acard is a structure (make-strncture @ vy), where Sis one ef the ayn te, "ianonds, ‘earrs, ‘Spades v ig a integer between 2 and 10, of one of the symbole if "Queen, "King, "Ace, fp hearls-svore: zat fr Conditions: fy FRE: Mo duplicate Card values in hand fe POST: The produced value her ~26 or a value between 0 and 25 fp Produces the score amplezi }) Uhearte-seore empty! => 0 fe (hearts-score [List (make-card ‘Hearts 3) (make-card ‘Spades 'gudxa) (mike-card 'Diemends qo de in hand for the game Hearts local [7 val QS is the value of the Queen of spades 13) define val 9 \e number of possible nen % a define max hearts 13) Fval-all un the value for a hand contaifih a define val-all -26) \ C fy heart7: card > Boolean ty Produces true if ¢ has suit os false otherwise define theart? © él reageS) ) ‘hearts and the queen of equal? (card ont e) (define num-hearts (Lengt\ (fal + has-93? is true if hand odntains the Queen of Spades, and false otherwise, (define has. des ‘Queen) hand) | | nenker? (nake-cat cond [jand (= num-hearts max-hearts) has-Q8?) val-all hearts) Testing heck-expact (hearts-score ng one card = 22 card worth 9, a heart, the queen af spades (hearts-acore spades $))) 9) (hearts-acore Hearts 10))) 1) thoarts-acore spades ‘gueen)}) 13 larger hand - no hearts, some hearts arts-score (List (make: gieen of spades, some hearts and queen of apades Diawonds 'hee) inake-card ‘spades 2) This document is for the exclusive use of hapatel. (make-card "iva 4))) 0) (check-oxpect (hearte-acore (List (nake-card ‘Diamonds 'Ree) Imake-card ipades 2) (make-card 'Cltins 6) (make-card ‘Hearts 4) (make-card "Dsemond "gneen) imake-card "rades 10) (make-card tHearts 7))) 2) (check-oxpect (hearte-acore (List (nake-card ‘Diamonds 'Ree) Imake-card tipades 2) (make-card 'Cltina 6) (make-cara ‘Hearts 4) (make-card "Spades "Queen) (make-card (make-card "Hearts 7))) 15) larger hand ~ al (chee! hearts but not queen of spades (list ‘Hearts 2) (make-card ‘Hea: 4) 6) 3) 20) (mske-card ‘Hearts 'Queen) (make-card 'Hea: (aake-cazd 77 larger hand - all hearts and queen of spades a (make-card ‘Hearts 4) (make-caby ‘Hearts (make-card ‘Hearts 6) (make-card (make-card ‘Hearts 8) (make-card ‘Maarts (make-card ‘Hearts 10) (make-2d (make-card ‘Hearts Seucen) (ne sar Mey (hake-sard ‘ioaets Meade ‘spades "queen! 26) larger hard - alt hearts but one end queen of spades x check-expect {hearts-score (list (make-card ‘Hearts 2)/(nahe-aard ‘Hearts 3) (make-card "Hea! (makeZard ‘Hearts § (make-card 'Heayfs 6)\Nqaké-card ‘Clubs 7) (make-card 'Heafts(2) (yike-card ‘Hearts 4) tes 'King) arts 'Ace) (make-card ‘Spades 'King))) 12) (check-expect (hearte-seoze (List (mak foarte "Hearts 'King) 10) (make-card ‘Hearts ' Zack) en) (make-card ‘Hearts 'King) 8 'Ace) (make-card ‘Spades 'Queen|}} 25) jon 4 (define-struct student ‘Qube A Student ia a structure \a@ke-s gent id g}, where id is a positive integer, a g is list of up to length 5\yhere each element in the list either a nunber between Vand 100 or one of the syabols 21ND, THR, SINC, oF "TN, (detine-atruct 9t jent-Limit (id max-courses) | PA Student-limit is a structure {make-student-limit idm), where id is a positive integer, and mis an integer between 2 and 6. ernest (listof Student} -> [listof Student-limit} FOST-Cond: Produced List is same length as resultalA Produces @ list containing information far students in resuitalA, including the student id th atudent in resulzalA, ard the maximun number of courses allaved based on grades for o Exanplest arses empty) => empty ursea (Iist {make-student 122 (1ist 6% 61 190 87 39) make-student 7860 (list §7 §1 50 70 80) make-student. 56 20)) This document is for the exclusive use of hapatel. (asst tow 49 67) (st 30 41 52 MWe Mwy) => (list (make-stment-lim- hake-sturent-limit 790 5) (make-etncant lim: bnate-stncen (make-etncant lim: (make-student-limit 110 5) nurses vesultelay Favade 1s defined as 10 and passing-qrade as 50 Fine strong-grade 80) (define parsiag-grade 30) G7 Usual-load is the standard course limit and aincload ds 2, ad 5 (define aln-Load 2) (define usual-: fe steongearade?: (union Nat ‘INC (WD ‘WF 'ENW. fy Produces true if grade is a numeric value (define (streng-grade? grade) {and (number? grade) [>= grade strong-grade) |) Boolean 30, and se otherwise fy novcredit?: (union Nat ‘INC ‘WD ‘WF 'DNW) > Boolean otherwise ( define (no credit? grade) =< fami (rimber? grade) (< grade ma ) dy inoreane limit?: Student -> Boolean G7 Producer true ifs hae 5 strong grads, am 2 otherwise Gefine jincreass Limit? =) beong-geade? (student (length sae SX. usus one student -> wax 7/0) 7 7 Produces the nimbO\ of coMtges Styflent 2 did not receive credit for, which ia alas and (andnap dy reduce by tothe mimber of (define [reduce-by =) length (filter no-credi® (student-grades 3)))) lead: Student > Stud mit } Produces the Student-limit for 5, with the same id, and containing ; the maximum allowed munker ef courses for the student (define [load 3) ake a student-limst structure make-student-1omit i with sane idas = ludent-id + and maximim allowed course limit nerease .oual-Load by 1 if the = had a very strong term linerease-lamit? 3) (addi usual-load) decrease the usual-Load (to a minimm of 2) by the number of unaucceasful coursea ela (itaxt min-load {- wsual-load (reduce-by 9) ))1))!1 Produce a now List by determt ig the new load for each atudent This document is for the exclusive use of hapatel. ina Load resmitelAa)) Testing (check-expest (nax-courses empty) emry: varions liste of | atudent with 5 qeades, checking different situations ~ all passed, strong qeades (check-expect (max purses {list {make-student 123 (list 99 95 99 36 (ltet (make-stient-limit 192 61) = all passed, at least one not strong ses {list {nake-stude: ” nt 5 $0 65 73.88 LOON}N 7298 20011) eo ‘me 73 98 100111 (max-courses (List (make-student 1271 (List 90 58 "Ras 100) )) (List (aake-etudent-limit 1271 4))) (max-courses (List (make~student 2271 (List 90 80 Tags Dyii)) (List (nake-student-limit 2271 4))) CC nake-student-Limit 3271 5))) - multiple poor or special grades 2 {list (make-student ay nake-student-Limit 672 4))) max-courses (list (make-student nake-student-Limit cate » max-courses (list (make~: i 1670) (L4ae tm Te 75 98 "¥0})) ‘nake-student-Limir we nes (list Sh SNgene RG (aise tar ne 73 88 14} )7 4 Fe “e check expact (max cow ‘we ‘INE 73 8% 'wD)))) ‘nake-student- maw cournes, (List (abke “4 176% (dae tin tINC 78 HD tH) (set (make Xgudent Nmit hs 8 21) Foor grades, Mb{ Lint (check-exper sk Feudent 1706 (List tow MINC 33.78 °¥}))) (ine (uaterseatesbyrinie 1708 2))) (check-expest (max-courses (list Amake-student 780 (List 'INW ‘IND 33 22 'WE)))) (last (make-student-limit 190 2))) = fever than 5 courses, all strong (check-expect (max-com 5 (list (nake-s dent 567 (list 46 61 65 S2)))) (set (make-student-limit 56? 5))) = fewer than 5 courses, all passed (check-expest (max-cou J (list (nake-s dent 3567 (list BS TL 98 92h) (set (make-student-limit 3567 5))) |< fewer than 5 courses, one uD heck-oxpect (max-courses (list (nake-student. 5 (list (make-student-limit 5671 5)) (oheck-expest (max-courses (ligt (make-atudent 234 (Iiat a9 "wp 92)))) (ist $8 90 twp 82y))) (ltet (make-stident-limit 224 5 = fewer than § courses, TNE/UR/ENW heck-oxpect (max-courses (list (nake-stude: (list 88 'ING "WE 92/1) (list (make-stident—limit 222 3))) (chest 333 (list 85" oxpect (max-courses (list (nake-stude: "way This document is for the exclusive use of hapatel. (ltet (make-stusient-timit 232 3))) (check-expect (max-courses (list imake (list (make-stndent-limit 996 9))) ; Multiple students, different situations covered - combination of abave = all grade Lists of length 5 anwdent 965 empty (check-axpact (max-courses (ist (make-atudent 123 (ist 90 65 60 96 57)) imake-student 111 (list 90 65 73.69 1n0)) imake-student 27 (list 90 45 73 95 1nm)) imake-student 271 (ist 90 TING 73.95 lnm) (nake-student 58 ‘WE 3 200!) (nake-student 80 72 8S ‘DNA } (aake-studeat 50.80 72 8 ‘uD} jnake-ztudent 670 80 ‘IIe 72.38 "HDI (aake-student 6701 (List 'WE ‘INC 73 86 'wD) (make-student L672 (List 'ENW MIN 73 95 "wD! ) jmake-ztudeat 170 (ligt 'INM "INC 73 99 'WE) (make-student 1703 (List 'ENW MING 72 "WD 'WF)) (aake-student 1703 (List 'ENd 1H 33 70 "WE! ) (make-student 780 (List 'DNW 'IA33 28 ‘uF! )) (make-student-limit 27 4) ( nake-ptudent-limit 271 4) \ make-etident-Lindt 622 4) ‘make-etudent-Limit 6721 3) fy check expect max-courses (List (make: 7 (High ae 91 98 529) (make: aig Hist e871 8 82)) (make-stuadgt 56/2 (list 89 91 ‘WD $2)) (make-stuien\234 (List 8& ‘uD 62)) 202 {list 88 ‘INC ‘WF 82) (make-student 222 (list 9% ‘WP ‘TRW)) (make-student S°% empty!) ) list (make-stus mit 567 5) imake-st mit 3567 5) make sts: mit 5671 5) imake-st mit 234 5) make sts: mit 222 3) imake-st mit 132 3) make-st mit 969 5)) example from assignment (oheok-expest max-courses (1ist (make-student 122 (list 86 $1 100 87 aD}) (make-student 7890 (list 57 51 50 70 80)) (make-student 5é (list 47 §1 50 79 69)) (make-student 2221 (list 'TMW 43 67) (make-stuciont 6 (list 38 41 52 "we ‘wD) This document is for the exclusive use of hapatel. This document is for the exclusive use of hapatel.

You might also like