Lab 1: Getting started
This lab introduces DrRacket and Beginning Student.
Lab attendance is required.
1 Sign up for Discord
We will use Discord to ask and answer questions, make announcements, and hang out. Sign up with the link we announced on Canvas when the course started. Change your nickname on Discord to the full name you’d like us to use in this class. Then, introduce yourself in the #introductions channel.
If you would like to talk to only instructors on Discord, type /breakout (with a forward slash at the beginning of the message) then hit Enter. This should create a “breakout channel” that only you and the staff can see.
Two safety tips on Discord (actually, on any network): First, enable two-factor authentication (next to your password setting). Second, don’t open any download you receive through a private message.
2 Pay attention to announcements
; Exercise 1 ; Answer:
Exercise 1. Alex started early on problem set 1 and submitted their work already on Wednesday. Unfortunately, they made a critical mistake and only got 5 out of 10 points. Where can they get personal feedback about their homework? How can they raise their grade on this assignment? When? By how much?
Exercise 2. Bri plans to work on problem set 1 this weekend and submit their work by Monday morning. According to this plan, what grade will they receive?
Exercise 3. When is problem set 2 due? When is midterm 1 scheduled? Where and when can you find your lab instructors at tutoring?
Exercise 4. Should you work with other students? Should you share your code with them? Instead of sharing code, what is one way to help other students if they get stuck? Instead of sharing code, what are two ways to get help if you get stuck?
Decide when you are going to work on this course every week.
Put at least 2 hours as a weekly appointment on your calendar. If you have never used a calendar, start using one, such as the one on your phone.
Then, enter the time you chose at When2meet. This way, y’all can find study buddies.
3 Arithmetic and constants
Make sure that the language level in DrRacket is set to “Beginning Student”. (Note: if you change the language level, it will not take effect until you hit the “Run” button.)
Exercise 6. Experiment using DrRacket’s Interactions Window as a calculator. See what operations you can use to calculate. Make sure to try fractions.
Exercise 7. Define a variable big-number to be a big number. (If you’re not sure how to define a variable, review Lecture 2: Definitions Exercise 1.) Then, define another variable bigger-number to be the result of multiplying big-number by itself. Finally, define a number that is bigger than bigger-number.
Hint: DrRacket comes with a help system called Help Desk, under the Help menu. Open the Help Desk and click “How to Design Programs Languages”, then click “Beginning Student”. You will get a reference for the Beginning Student language. You can also search in the Help Desk for documentation about a particular function, such as expt.
4 Images
Exercise 8. Download a small image off the Web and insert it into your Definitions Window. Use define to give it a descriptive name. Examples: vehicles, plants, foods, etc.
Exercise 9. Using the rectangle function provided by the 2htdp/image library, create a rectangle that is a little bigger than the image you downloaded. (If you’re not sure how to use a function, review Lecture 1: DrRacket and arithmetic Exercise 12.)
Hint: DrRacket comes with a help system called Help Desk, under the Help menu. Open the Help Desk and click “How to Design Programs Teachpacks”, scroll down to “HtDP/2e Teachpacks”, then click “Basic Images”. You will get a reference for the 2htdp/image library. You can also search in the Help Desk for documentation about a particular function, such as rectangle.
Exercise 10. Using the overlay function provided by the 2htdp/image library, put the image you downloaded in Exercise 8 inside the rectangle you created in Exercise 9.
5 Functions
Exercise 13. Define a function that, when given a diameter and a height, will produce an image that can be printed, folded up, and taped together to make the cylinder of the given diameter and height. Name your function can. For example, the images you just created should be just as well produced by (can 75 105) and (can 85 40).
Exercise 14. Define a function that, when given a diameter and a height, will compute the surface area of the cylinder of the given diameter and height.
syntax error, when you write something that DrRacket doesn’t recognize as a program
run-time error, such as when you provide the wrong kinds of inputs to an operation
logical error, when your program produces an answer, but it’s the wrong answer
6 Food
(overlay (triangle 30 "solid" (make-color 190 70 10)) (triangle 60 "solid" (make-color 250 230 190)))
Exercise 17. What happens if you feed the number -1234567/89 to the function you just defined? What range or kind of numbers can your function actually handle correctly? Write down your answer clearly.
7 Animation
Exercise 18. Define a function which produces an image when given a number. The image produced must have the same size no matter what number is given. For instance, you could define a function that places a circle with the given radius in the middle of a large empty scene.
Exercise 19. Use the function you just created, along with animate, to produce an animation. Remember that using something means putting its name in your code.
That’s it for this lab! Your lab instructors will grade your work and give you friendly feedback. For later reference, you should also save your work using the Handin server, as assignment lab1.