;======== ; Fall 2024 - CS 111 ; Week 2 Lab Exercise ; ; date: 2024-09-06 ;======== ; make the definitions and functions from the 2htdp/image module ; available in this file (require 2htdp/image) ;======== ; REMINDER: Pair-programming: ; * TWO students working at ONE computer ; * ONE student, student A, OPENS a copy of this file in ; DrRacket ; * the OTHER student, student B, says what to type, and student A ; types it into this file ; * BOTH students should be looking at the shared computer screen, ; and discussing concepts/issues along the way ;======== ;======== ; USING pair-programming: ; 1. COPY and PASTE the contents of this file into a DrRacket ; Definitions window ; 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! ; ******** ; ; 3. RUN the resulting file frequently along the way, fixing ; any errors that arise (and SAVE the definitions window ; to the driver's Google Drive, say as lab2.rkt) ; ; (Need help with an error? Or just have a question? ; * If needed, comment out the line(s) with an error in the, ; meantime, putting ; at the beginning of each such line ; * Let the lab instructor know if you have a question ; * Note that if they are helping others, it might be a while until ; they can get to you. Try to work on later problems while you ; wait, and it is also fine for pairs to help each other!) ; ; 4. When you are done, use Gmail to MAIL a copy of the ; resulting filled-in lab2.rkt file to BOTH of you ; 5. And, EACH of you should SUBMIT this file on Canvas ;======== ;===== ; Leave a blank line, and then put COMMENT(s) containing BOTH ; of your names: ;======== ; PROBLEM 1 - DEFINING and USING named constants ; (you only need signatures and purpose statements for FUNCTIONS -- ; they are NOT needed for Problem 1!) ;======== ;----- ; 1 part a ; Remember: MY-CHOICE, PURPLE-STAR, MAX-YOG, and BLUE-HEX are examples of ; named constants in the Week 2 posted examples ; ; Define a named constant PAIR-NAMES of type string ; whose value is your names. ; Now write the now-simple-expression PAIR-NAMES, ; and when you run this, ; you should see PAIR-NAMES now has that value. ;----- ; 1 part b ; Reminder: function string-length expects a string, and returns the ; number of characters in that string. ; ; Write a compound expression using PAIR-NAMES whose value will be ; the number of characters in PAIR-NAMES ;----- ; 1 part c ; Consider the functions overlay and text; their signatures and purpose ; purpose statement comments are given in the ; "More DrRacket Tidbits" handout ; (and of course they are described in the Racket Documentation ; for 2htdp/image, also) ; ; Write a compound expression, using overlay, text, and other image ; operations that you choose, that uses PAIR-NAMES within it, ; whose value will be an image of your choice with an image-version ; of PAIR-NAMES' value centered upon it. ;----- ; 1 part d ; Define a named constant, with a nicely-descriptive name written in ; all-uppercase, whose value is a compound expression of ; type image making use of at least two different functions from ; 2htdp/image. ; Now write your new named constant as a simple expression, ; and when you run this, ; you should see that it has an image value. ;----- ; 1 part e ; NOTE: function image-width expects an image, and returns the ; width of that image in pixels. ; ; Write a compound expression using the named constant you defined ; in 1 part d whose value is the WIDTH of your named constant ; image in pixels. ;----- ; 1 part f ; Likewise, function image-height expects an image, and returns the ; height of that image in pixels. ; ; Write a compound expression using the named constant you ; defined in 1 part d whose value is the HEIGHT of your ; named constant image in pixels. ;======== ; PROBLEM 2 - walking through the DESIGN RECIPE steps to ; design a function ;======== ;----- ; REMEMBER: these steps are demo'd in the posted Week 2 Lecture 2 ; examples, in 111lect02-2.rkt, designing function triple ; ; AND: note that now there's a posted "graphic design recipe helper" ; on the course Canvas home page and public course web site, ; to remind you of these design recipe steps, also! ;----- ; FIRST, you THINK about the desired problem, and the kinds of values ; it involves. ; Assume you would like a function to give a friendly greeting to ; someone by name. Strings work well for representing names and ; greetings. ;----- ; 2 part a ; After further consideration, it is decided the function's name ; will be say-hi, and you want a name-specific greeting ; based on a name. ; COMPLETE an appropriate signature comment for this function: ; signature: ;----- ; 2 part b ; COMPLETE an appropriate purpose statement comment for this ; function: ; purpose: expects ; and returns ;----- ; 2 part c ; Write a function header for this function, giving a good descriptive ; name for its parameter, and FOR NOW put ... ; for its function body: ;----- ; 2 part d ; Write at least two check-expect expressions with two ; example expressions USING/TESTING your ; function-in-progress, with two DIFFERENT names: ;----- ; 2 part e ; Consider: how did you figure out the expected result for ; each of your tests? ; How could you do that in Racket? Where does your ; parameter fit in that? ; GO BACK UP to 2 part c, and NOW replace the ... in its ; function body with an expression, using the parameter, ; that will give the result ; desired. ;----- ; 2 part f ; Write at least one example call of your function here, so ; you can see its actual result in the Interactions window ; when this is run. ;----- ; Now SAVE your Definitions window, and click Run -- ; * Do your tests pass? ; * Does the resulting greeting for your ; example call from 2 part f look reasonable? ; If not, debug your function and its tests as needed. ; If so, you are done with this lab exercise. ;===== ; Remember: once you have Run these and are satisfied with them, ; * Use Gmail to EMAIL copies of this file lab2.rkt ; to BOTH of you ; ; * BOTH of you should submit this file on Canvas: ; * go to the course Canvas site (canvas.humboldt.edu, ; select your course CS 111) ; * click on "Modules" on the left-hand-side ; * scroll down to the "Lab Exercises" section ; * click the "Week 2 Lab Exercise" link ; * follow the Canvas instructions for uploading your ; Racket file. ;=====