CS100

55aann
Assignment61.pdf

CS​ ​100​ ​–​ ​Critical​ ​Thinking​ ​w/​ ​Computers Assignment​ ​#6​ ​-​ ​80​ ​points​ ​total Due​ ​October​ ​13th​ ​via​ ​Canvas.

Part​ ​1​ ​Activity: 20​ ​points​ ​​ ​(2​ ​points​ ​each​ ​question) One​ ​of​ ​the​ ​goals​ ​here​ ​is​ ​to​ ​learn​ ​how​ ​expressions​ ​are​ ​written​ ​in​ ​Scheme. Go​ ​to​​ ​​www.wescheme.org​,​ ​and​ ​click​ ​on​ ​“Log​ ​In”. The​ ​site​ ​will​ ​then​ ​transfer​ ​to​ ​you​ ​​myHumboldt​​ ​to​ ​login​ ​to​ ​authenticate​ ​your​ ​account.​ ​When​ ​it​ ​does,​ ​enter​ ​your​ ​username​ ​(​without the​ ​humboldt.edu)​ ​and​ ​your​ ​HSU​ ​password. At​ ​this​ ​time,​ ​you​ ​can​ ​click​ ​-​ ​start​ ​a​ ​new​ ​program,​ ​give​ ​your​ ​project​ ​a​ ​name​ ​so​ ​it​ ​will​ ​saved​ ​-​ ​something​ ​like​ ​CS100​ ​Assignment​ ​#6. Add​ ​comments​ ​(comments​ ​begin​ ​with​ ​a​ ​semicolon)​ ​to​ ​the​ ​top​ ​of​ ​your​ ​program​ ​in​ ​the​ ​definitions​ ​window​ ​with​ ​your​ ​name​ ​and assignment​ ​number​ ​like: ;​ ​Michael​ ​Bradley ;​ ​Assignment​ ​#6 Type​ ​in​ ​the​ ​following​ ​expressions​ ​in​ ​the​ ​definitions​ ​window​ ​-​ ​run​ ​your​ ​program​ ​to​ ​view​ ​the​ ​results​ ​in​ ​the​ ​interactive​ ​window. These​ ​will​ ​all​ ​produce​ ​a​ ​number​ ​as​ ​a​ ​result​ ​–​ ​none​ ​of​ ​them​ ​should​ ​cause​ ​an​ ​error.​ ​​ ​(use​ ​a​ ​string​ ​in​ ​quotes​ ​to​ ​label​ ​each​ ​problem​ ​and answer-​ ​for​ ​example​ ​#1​ ​and​ ​#2​ ​below) ;​ ​Part​ ​I​ ​​ ​(put​ ​a​ ​comment​ ​labeling​ ​Part​ ​I​ ​in​ ​your​ ​code​ ​then​ ​write​ ​the​ ​following​ ​code)​ ​​ ​When​ ​done​ ​click​ ​run​ ​to​ ​verify​ ​all​ ​is​ ​working fix​ ​any​ ​errors.

1. "Part​ ​I​ ​#1" (+​ ​7​ ​4)

2. "Part​ ​I​ ​#2" (/​ ​24​ ​8)

3. (exp​ ​2)​ ​​ ​remember​ ​to​ ​add​ ​the​ ​"string" 4. (sqrt​ ​18) 5. (+​ ​(*​ ​5​ ​4)​ ​(*​ ​3​ ​2)) 6. (/​ ​(-​ ​7​ ​3)​ ​(-​ ​5​ ​2)) 7. (-​ ​(/​ ​(*​ ​6​ ​5)​ ​3)​ ​(+​ ​4​ ​2)) 8. (sqr​ ​(+​ ​7​ ​5)) 9. (modulo​ ​17​ ​5) 10. (expt​ ​(-​ ​10​ ​7)​ ​(*​ ​3​ ​5))

Part​ ​2​ ​–​ ​Writing​ ​Scheme​ ​expressions 20​ ​points​ ​​ ​(2​ ​points​ ​each​ ​question) For​ ​the​ ​following​ ​expressions,​ ​write​ ​the​ ​expression​ ​exactly​ ​as​ ​presented.​ ​in​ ​the​ ​Scheme​ ​language​ ​in​ ​your​ ​definitions​ ​window​ ​- label​ ​each​ ​with​ ​a​ ​string​ ​describing​ ​the​ ​problem​ ​number​ ​-​ ​all​ ​should​ ​produce​ ​a​ ​number.​ ​​ ​When​ ​done​ ​click​ ​run​ ​to​ ​verify​ ​all​ ​is working​ ​fix​ ​any​ ​errors. For​ ​example, ​ ​​ ​​ ​​7​ ​+​ ​5 ​ ​​ ​​ ​​ ​​ ​4​ ​​ ​​ ​​ ​​ ​​ ​Would​ ​be​ ​(/​ ​(+​ ​7​ ​5)​ ​4)​​ ​(NOT​ ​as​ ​12/4​ ​or​ ​3) ;​ ​Part​ ​II

1. "Part​ ​II​ ​#1"​ ​(don't​ ​forget​ ​to​ ​label​ ​each​ ​with​ ​a​ ​string) 13​ ​+​ ​12​ ​​ ​(you​ ​put​ ​this​ ​in​ ​the​ ​definition​ ​window​ ​as​ ​a​ ​Scheme​ ​expression)

2. 6​ ​+​ ​8​ ​*​ ​2 3. 9​ ​-​ ​(6​ ​/​ ​2)​ ​+​ ​(2​ ​*​ ​2) 4. (​ ​6​ ​*​ ​6​ ​)​ ​–​ ​(​ ​7​ ​*​ ​5​ ​) 5. 13​ ​​ ​/​ ​(​ ​6​ ​+​ ​7​ ​) 6. 4​ ​+​ ​5​ ​+​ ​6​ ​+​ ​7​ ​+​ ​8​ ​+​ ​9 7. (​ ​24​ ​/​ ​8​ ​)​ ​+​ ​(​ ​16​ ​/​ ​2​ ​)​ ​+​ ​(​ ​30​ ​/​ ​5​ ​) 8. ½​ ​+​ ​⅓​ ​+​ ​¼ 9. (7​ ​+​ ​8)​ ​/​ ​(4​ ​+​ ​1) 10. (81/9)​ ​​ ​*​ ​​ ​(27/3)​ ​​ ​*​ ​((16​ ​+​ ​2)​ ​/​ ​(1​ ​+​ ​1))

Part​ ​3​ ​–​ ​Writing​ ​a​ ​Scheme​ ​function  20​ ​points​​ ​​ ​Label​ ​"Part​ ​III" Now,​ ​click​ ​the​ ​“Recipe”​ ​button,​ ​and​ ​type​ ​in​ ​the​ ​blanks​ ​as​ ​shown​ ​below​ ​(view​ ​PDF​ ​version​ ​of​ ​this​ ​assignment​ ​to​ ​see​ ​image​ ​-​ ​link at​ ​top​ ​of​ ​this​ ​assignment)​ ​to​ ​create​ ​the​ ​function​ ​​add3​​ ​using​ ​the​ ​method​ ​demonstrated​ ​in​ ​class.​ ​It​ ​takes​ ​a​ ​​number​​ ​as​ ​input​ ​as​ ​gives a​ ​​number​​ ​as​ ​output,​ ​where​ ​the​ ​output​ ​number​ ​will​ ​be​ ​3​ ​greater​ ​than​ ​the​ ​input​ ​number.

Now​ ​click​ ​“Insert”.​ ​You​ ​will​ ​see​ ​the​ ​Scheme​ ​program​ ​show​ ​up​ ​in​ ​your​ ​definition​ ​side. Below​ ​the​ ​inserted​ ​definition​ ​type​ ​the​ ​expression​ ​​(add3​ ​17)​,​ ​run​ ​your​ ​program​ ​and​ ​this​ ​problem​ ​should​ ​return​ ​with​ ​the​ ​number 20​..

Part​ ​4​ ​–​ ​Creating​ ​your​ ​own​ ​Scheme​ ​function 20​ ​points​ ​​label​ ​"Part​ ​IV" Using​ ​the​ ​instructions​ ​from​ ​the​ ​previous​ ​exercise​ ​as​ ​an​ ​example,​ ​examine​ ​the​ ​function​ ​​add3​​ ​and​ ​write​ ​a​ ​function​ ​similar​ ​to​ ​it called​ ​​multiply5​​ ​that​ ​will​ ​take​ ​a​ ​number​ ​as​ ​input​ ​and​ ​multiply​ ​that​ ​number​ ​by​ ​5​ ​as​ ​its​ ​output.​ ​Use​ ​the​ ​“Recipe”​ ​feature​ ​in WeScheme.​ ​Once​ ​completed,​ ​below​ ​the​ ​inserted​ ​definition​ ​type​ ​the​ ​expression​ ​(multiply5​ ​​ ​5),​ ​run​ ​your​ ​program​ ​and​ ​this​ ​problem should​ ​return​ ​with​ ​the​ ​number​ ​25.. Copy​ ​and​ ​paste​ ​your​ ​definitions​ ​(which​ ​should​ ​contain​ ​all​ ​the​ ​problem​ ​from​ ​above)​ ​into​ ​a​ ​wordpad​ ​(or​ ​other text​ ​document)​ ​save​ ​it​ ​and​ ​upload​ ​to​ ​Canvas​ ​to​ ​be​ ​graded.​ ​​ ​I​ ​will​ ​run​ ​these​ ​programs​ ​so​ ​make​ ​sure​ ​they​ ​work. Example​ ​what​ ​what​ ​the​ ​program​ ​will​ ​look​ ​like: ;​ ​Michael​ ​Bradley ;​ ​Assignment​ ​#6

;​ ​Part​ ​I "Part​ ​I​ ​#1" (+​ ​7​ ​4)

"Part​ ​I​ ​#2" (/​ ​24​ ​8)

;​ ​you​ ​continue​ ​with​ ​the​ ​rest​ ​of​ ​the​ ​problems​ ​in​ ​part​ ​I

;​ ​Part​ ​II "Part​ ​II​ ​#1" (+​ ​13​ ​12)

"Part​ ​II​ ​#2" (-​ ​(*​ ​6​ ​​ ​6​ ​)​ ​(*​ ​7​ ​​ ​5​ ​))

;​ ​you​ ​continue​ ​with​ ​the​ ​rest​ ​of​ ​the​ ​problems​ ​in​ ​part​ ​II

;​ ​Part​ ​III ;​ ​yours​ ​will​ ​be​ ​an​ ​add​ ​function

;​ ​minus2​ ​:​ ​number​ ​->​ ​number "Part​ ​III" (EXAMPLE​ ​(minus2​ ​3)​ ​1)

(EXAMPLE​ ​(minus2​ ​5)​ ​3) (define​ ​​ ​(minus2​ ​input-number) ​ ​​ ​(-​ ​input-number​ ​2))

(minus2​ ​20) (minus2​ ​30)

;​ ​Part​ ​IV ;​ ​yours​ ​will​ ​be​ ​an​ ​multiply​ ​function "Part​ ​IV" ;​ ​divide3​ ​:​ ​number​ ​->​ ​number (EXAMPLE​ ​(divide3​ ​9)​ ​3) (EXAMPLE​ ​(divide3​ ​6)​ ​2) (define​ ​​ ​(divide3​ ​input-number) ​ ​​ ​(/​ ​input-number​ ​3))

(divide3​ ​30) (divide3​ ​8) The​ ​end.