;======== ; Fall 2026 - CS 111 ; Week 4 Lab Exercise - save as lab4.rkt ; ; date: 2026-09-18 ;======== ;----- ; this file will use definitions and functions from these modules: (require 2htdp/image) (require 2htdp/universe) ;======== ; NOTE: ; * To receive credit for this lab exercise, you must: ; * be present during your lab section, ; either in BSS 313 or in the lab Zoom session, ; based on your lab section ; * participate appropriately in a pair, ; either in BSS 313 or in a Zoom breakout room ; ;======== ; USING pair-programming: ; 1. COPY and PASTE the contents of this file into a ; DrRacket Definitions window, and save as: ; ; lab4.rkt ; ; 2. ADD comments and expressions TO THIS as specified below ; (one student saying what to type, the other student typing it ; into DrRacket) ; ; ******** ; * DO NOT DELETE THE COMMENTS! They speed up grading! ; ******** ; ; * remember: it is a class style standard to put a ; BLANK LINE between each comment-block and an expression ; following it ; ; 3. SAVE the contents of your definitions window frequently ; as you are working, to the driver's Google Drive, ; using a file name of lab4.rkt. ; ; 4. RUN the resulting file frequently as you are working, ; clicking the Run button in the top-right corner ; each time, looking over your expressions' values in ; the Interactions window (the bottom window), and fixing ; any errors that arise. ; ; 5. When you are done, use Gmail to MAIL a copy of the ; resulting filled-in lab4.rkt file to BOTH of you ; ; 6. And, EACH of you should SUBMIT this file to Canvas BEFORE you ; leave lab. ; ; 7. REMEMBER to also answer the ; "Week 4 Lab Exercise - Pair-Programming Peer Review Survey" ; in Canvas, posted along with this lab exercise, by ; 11:59 pm TONIGHT (Friday, September 18) ;======== ;===== ; Leave a blank line, and then put COMMENT(s) containing BOTH ; of your names (include first AND last names) ;======== ; PROBLEM 1 - READING and MODIFYING a function with a cond ; expression ; [adapted from ; http://web.cs.wpi.edu/~cs1101/a05/Labs/lab1.html, ; as found from EngageCSEdu] ;======== ;-------- ; Problem 1 - PART 1 ;-------- ; below is a function definition, BUT, in the given lab exercise ; file, its tests/check- expressions are COMMENTED OUT. ; ; *** RUN THIS AS IT IS RIGHT NOW *** ; ; YOU SHOULD SEE THE FOLLOWING: ; * NO expression values in the Interactions window ; (because this only defines the function at this point) ; ; * the function body appears with a DARK background ; with ORANGE letters [***IF*** you are not running ; in dark mode] ; * IMPORTANT: this is DrRacket's way of HIGHLIGHTING ; these expressions, to say that they were NOT EXECUTED ; in this latest Run ; * this CAN mean (as it does here) that you are missing ; tests/check- expressions for such a function ;----- ; signature: babel-greet: string -> string ; purpose: expects the name of a language, Spanish, French, ; Japanese, or English, and returns a suitable ; greeting in that language. ; Returns "Don't know" if given a language it ; does not recognize. (define (babel-greet lang) (cond [(string=? lang "Spanish") "Hola"] [(string=? lang "French") "Bonjour"] [(string=? lang "Japanese") "Konnichiwa"] [(string=? lang "English") "Hello"] [else "Don't know"] ) ) ; at beginning of lab exercise: tests below are commented ; out, to make a point described above! ; ;(check-expect (babel-greet "Spanish") "Hola") ;(check-expect (babel-greet "French") "Bonjour") ;(check-expect (babel-greet "Japanese") "Konnichiwa") ;(check-expect (babel-greet "English") "Hello") ;(check-expect (babel-greet "Texan") "Don't know") ;-------- ^ ; Problem 1 - PART 2 | ;-------- | ; *** ABOVE, | ; *** on the next line RIGHT after ; *** the check-expect for (babel-greet "Texan"), ; *** ADD the compound expression: ; ; (babel-greet "Spanish") ; ; *** and THEN, RUN THIS AGAIN *** ; ; YOU SHOULD SEE THE FOLLOWING: ; * the 1st branch in babel-greet is NOT highlighted now -- ; it *was* executed in this latest run. ;-------- ; Problem 1 - PART 3 ;-------- ; *** REMOVE the ;'s before each check-expect for babel-greet *** ; *** (that is, UNCOMMENT the check-expect expressions) *** ; ; *** and THEN, RUN THIS AGAIN *** ; ; YOU SHOULD SEE THE FOLLOWING: ; * NO expressions in babel-greet are highlighted now -- ; all *WERE* executed in this latest run. ;-------- ; Problem 1 - PART 4 ;-------- ; *** ABOVE, | ; *** on the next line RIGHT after (babel-greet "Spanish"), ; *** ADD an expression calling babel-greet with ; *** argument "Wiyot" ; ; *** and THEN, RUN THIS AGAIN *** ; ...what is the value of this babel-greet expression? ; ; * According to https://www.wiyot.us/DocumentCenter/View/112 ; ========================================= ; *** one Wiyot greeting is "Ha’wa’lou" *** ; ========================================= ; ; *** ABOVE, | ; *** on the next line RIGHT after (babel-greet "Wiyot"), ; *** ADD a test/check-expect that should PASS ; *** if babel-greet were able to properly handle an ; *** argument of "Wiyot" ; ; *** THEN, ; *** MODIFY babel-greet so that this NEW "Wiyot" test PASSES, ; *** so that babel-greet DOES return an appropriate greeting ; *** for "Wiyot" ;======== ; PROBLEM 2 - write a function size->quant ;======== ; Consider a situation where drink sizes are expressed with the ; following words (from: ;https://www.eater.com/2011/1/17/6701687/starbucks-to-launch-a-31-oz-big-gulp-of-coffee-the-trenta): ; size name: "short" "tall" "grande" "venti" "trenta" ; # ounces: 8 12 16 20 31 ; ; Using the DESIGN RECIPE, design a function size->quant that ; expects the *NAME* of one of these drink sizes, and ; returns just the *NUMBER* of ounces you get for that ; drink size. ; (that is, for example, if you call it with an argument of "short", ; it returns just the number 8) ; But what if someone calls this with a size name not in this list? ; Your function should return 0 in that case. ; ; (NOTE: this is what HtDP/2e Section I - Chapter 4 ; calls ENUMERATION-style data, listing out the ; separate possible values.) ; Since there are 5 possible, separate values, ; plus the user may give a "bad" value, ; MAKE SURE sure you include ; AT LEAST SIX appropriate check-expressions/tests ; for size->quant ;======== ; PROBLEM 3 - write a function judge-carbs ;======== ; Someone has decided that they want to judge a food as ; low-carbohydrate if it has less than or equal to 10 grams ; of carbohydrates per serving. ; And, if > 10 grams and <= 20 grams, they want to judge it as ; moderate-carbohydrate, ; and if > 20 grams, they want to judge it as high-carbohydrate. ; ; Using the DESIGN RECIPE, design a function judge-carbs that ; expects the *number* of carbohydrates some food has in ; a serving, and returns whether, based on the above, it ; is "lo-carb", "mod-carb", or "hi-carb". ; (that is, for example, if you call it with an argument of 15, ; it returns just the string "mod-carb") ; ; (NOTE: this is what HtDP/2e Section I - Chapter 4 ; calls INTERVAL-style data, describing the data as ranges ; of numbers.) ; Since there are 3 intervals, ; and thus two BOUNDARIES between those 3 intervals, ; MAKE SURE you include ; AT LEAST FIVE appropriate check-expressions/tests ; for judge-carbs ;===== ; Remember: once you have Run these and are satisfied ; with them, ; * Use Gmail to EMAIL copies of this file lab4.rkt ; to BOTH of you ; ; * BOTH of you should submit this file to Canvas ; BEFORE you leave lab. ; ; * ALSO answer the ; "Week 4 Lab Exercise - Pair-Programming Peer Review Survey" ; in Canvas, posted along with this lab exercise, by ; 11:59 pm TONIGHT (Friday, September 18) ;=====