Assignment 03 1 • Unless otherwise indicated in the question, you

CS 115 – Spring 2017
Assignment 03
Due: Wednesday, May 31 at 10:00 a.m.
• Unlessotherwiseindicatedinthequestion,youmayuseonlythebuilt-infunctionsandspecialforms
introducedinthelectureslidesfromCS115uptoandincludingthemodulescoveredbythis
assignment.Alistoffunctionsdescribedineachmoduleofthelectureslidescanbefoundat
https://www.student.cs.uwaterloo.ca/~cs115/built_in
• Forthisandallsubsequentassignments,youareexpectedtousethedesignrecipewhenwriting
functionsfromscratch,includinghelperfunctions.
• DownloadtheinterfacefilefromthecourseWebpagetoensurethatallfunctionnamesarespelled
correctly,andeachfunctionhasthecorrectnumberandorderofparameters.
• Readeachquestioncarefullyforrestrictions.
• Testdataforallquestionswillalwaysmeetthestatedassumptionsforconsumedvalues.
• Donotcopythepurposedirectlyfromtheassignmentdescription.Thepurposeshouldbewrittenin
yourownwordsandincludereferencestotheparameternamesofyourfunctions.
• Thesolutionsyousubmitmustbeentirelyyourownwork.Donotlookupeitherfullorpartialsolutions
ontheInternetorinprintedsources.
• Donotsendanycodefilesbyemailtoyourinstructorsoranyothercoursestaff.Coursestaffwillnot
acceptitasanassignmentsubmission.Coursestaffwillnotdebugcodeemailedtothem.
• YoumaypostgeneralassignmentquestionsusingthediscussiongroupsonWaterlooLEARN.Choose
ConnectàDiscussions.Readtheguidelinesforpostingquestions.DoNOTpostanycodeaspartof
yourquestions.
• CheckMarkusandyourbasictestresultstoensurethatyourfileswereproperlysubmitted.Inmost
cases,solutionsthatdonotpassthebasictestswillnotreceiveanycorrectnessmarks.
• Anystringorsymbolconstantvaluesmustexactlymatchthedescriptionsinthequestions.Any
discrepanciesinyoursolutionsmayleadtoaseverelossofcorrectnessmarks.Basictestsresultswill
catchmany,butnotnecessarilyallofthesetypesoferrors.
• ReadthecourseWebpageformoreinformationonassignmentpoliciesandhowtoorganizeand
submityourwork.FollowtheinstructionsintheStyleGuide.Yoursolutionsshouldbeplacedinfiles
a03qY.rkt,whereYisavaluefrom1to3.
Languagelevel:BeginningStudent
Coverage:Module3
1. WriteaRacketfunctioncalledvalid-name?thatconsumesfournonemptyandcase-sensitive
stringsfname,lname,s1,ands2,andanaturalnumbern,whichisgreaterthan0.Thefunction
producestrueiffnamestartswiths1,lnameendswiths2,andthelengthoffnameandlnamewhen
concatenatedisgreaterthann.Notethats1isnotlongerthanfnameands2isnotlongerthanlname.
Examples:
• (valid-name? "Emily" "Clarke" "Em" "arke" 10) => true
• (valid-name? "Emily" "Clarke" "mi" "ark" 8) => false
1
CS 115 – Spring 2017
Assignment 03
Due: Wednesday, May 31 at 10:00 a.m.
2. WriteaRacketfunctiondata-typethatconsumesaninput,value(ofoneofthefollowingtypes:
number,string,orsymbol),andproducesoneofthefollowingstrings:
• "String. Length >= 10",
• "String. Length < 10",
• "Symbol",
• "Integer. Positive value",
• "Integer. Negative value",
• "Zero",
• "Number. Non-integer value".
Someexamples:
• (data-type
• (data-type
• (data-type
• (data-type
• (data-type
"To be or not to be") => "String. Length >= 10"
-1) => "Integer. Negative value"
pi) => "Number. Non-integer value"
0) => "Zero"
8.0) => "Integer. Positive value"
Note:
• YoumayNOTusenestedconditionsandyoumayNOTusehelperfunctions,
• Youmayuseand&or,
• Thestringsthefunctionmightproducemustmatchthoseprovidedinthequestionexactlyinorder
togetanymarks-anytypographicalerrorinthestringwillbemarkedasincorrect.
3. Ashoestorecarriessixshoestyles.Duringashoesalesevent,customerswhoboughtthreeshoes
withinacertainperiodweregivenadiscountof2%onthefirstshoepurchased,5%onthesecond
shoe,and10%onthethirdshoe.Anadditionaldiscountof5%oftheoriginalpriceisappliedtoextra
smallandextralargeshoesizes.Extrasmallandextralargeshoesarerepresentedwith"X",while
othershoesizesarerepresentedwith"Y".
Eachshoeisrepresentedbyasinglecharacter,forexample,theballetshoeis"B",converseis"C",
galeshis"G",jellyis"J",loafersis"L",andmoccasinis"M".Pricesareasfollows:"B"is$10,"C"is$40,
"G"is$70,"J"is$25,"L"is$90,and"M"is$120.Youmayassumeallshoesareinstock.
Thethreeshoesboughtbyacustomerisrepresentedbyastring,shoes,andshoesizesare
representedbyanotherstring,sizes.Lengthofshoesisthree,andlengthofsizesisthree.The
firstcharacterrepresentsthefirstshoebought,thesecondcharacterrepresentsthesecondshoe,and
thethirdcharacterrepresentsthethird.Charactersinsizescorrespondtothecharactersinshoes.
WriteaRacketfunctionshoe-costthatconsumestwostrings,shoesandsizes,andproduces
thetotalamountpaidbythecustomer.
2
CS 115 – Spring 2017
Assignment 03
Due: Wednesday, May 31 at 10:00 a.m.
Forexample:
• (shoe-cost "CGJ" "XYY") => 126.2
§ Discountonshoes"CGJ"(40*2%)+(70*5%)+(25*10%)=6.8
§ Discountonsizes"XYY"(40*5%)+(70*0%)+(25*0%)=2
§ (40+70+25)–(6.8+2)=126.2
• (shoe-cost "LBM" "YXY") => 205.2
§ Discountonshoes"LBM"(90*2%)+(10*5%)+(120*10%)=14.3
§ Discountonsizes"YXY"(90*0%)+(10*5%)+(120*0%)=0.5
§ (90+10+120)–(14.3+0.5)=205.2
4. Forthisquestion,youwillperformstep-by-stepevaluationsofRacketprogramsbyapplying
substitutionrulesuntilyoueitherarriveatafinalvalueoryoucannotcontinue.Youwilluseanonline
evaluationtoolthatwehavecreatedforthispurpose.Tobegin,visitthiswebpage:
https://www.student.cs.uwaterloo.ca/~cs115/stepping/
Note:
•
YouwillneedtoauthenticateyourselfusingyourQuest/WatIAmIDandpassword.
•
Onceyouareloggedin,trythe“Warmupquestions”andcompletetheproblemsunder
Assignment3.
•
Youcanre-enterastepasmanytimesasnecessaryuntilyougetitright,sokeeptryinguntilyou
completelyfinisheveryquestion.
•
Allyouhavetodoiscompletethequestionsonline,wewillberecordingyouranswersasyougo,
andthereisnofiletosubmit.
•
NotehoweverthatyouarenotdonewithaquestionuntilyouseethemessageQuestioncomplete!
•
Youshouldseethisonceyouhavearrivedatafinalvalueandclickedon“simplestform”(or“Error”,
Dependingonthequestion).
•
YoushouldnotuseDrRacket’sSteppertohelpyouwiththisquestionforseveralreasons.First,as
mentionedinclass,DrRacket’sevaluationrulesareslightlydifferentfromtheonespresentedin
class,butweneedyoutousetheevaluationrulespresentedinclass.Second,inanexamsituation,
youwillnothaveDrRacket’sSteppertohelpyou,andtherewilldefinitelybestep-by-step
evaluationquestionsonatleastoneoftheexams.
•
Thebasictestsforthisassignmentwilltellyouwhetherornotwehavearecordofyourcompletion
ofthestepperproblems.
•
TherewillbenoautomaticbasictestmailsenttoUWaterlooemailuponfinishingthisquestion.
However,youmayrequestforabasictestoryoucouldsubmitanotherfiletoreceivethebasictest
forthisquestion.
3