This lab will introduce using DrRacket and Beginning Student, using the Handin Server, and defining simple functions.
Start DrRacket. Make sure that the language level is set to "Beginning Student" (Note: if you change the language level, it will not take effect until you hit the "Run" button).
Exercise 1: Experiment using DrRacket’s Interactions Window as a calculator. See what operations you can use to calculate. Make sure to try fractions.
Exercise 2: Define a variable big-number to be a big number. 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.
Exercise 3: There are three kinds of errors you can make when writing a program in DrRacket. Come up with examples of each and try them out. Examine any error messages you get back.
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
Exercise 4: Define a function that when given an integer that represents distance in miles will return the time (in hours) it takes to travel that distance when going 60 MPH. Write your function in the Definitions Window, click Run, then use the Interactions Window to test your function.
Exercise 5: Define a function that given an integer representing time (in minutes) will return the distance traveled when going 70 MPH, rounding up to whole miles.
Exercise 6: Define a function that converts a temperature in Fahrenheit to a temperature in Celsius. Here is the formula.
Exercise 7: Define a function that converts a temperature in Celsius to a temperature in Fahrenheit. In the Interactions Window, apply this function to an integer and apply the function from Exercise 4 to the result and see that you get the same number back.
Hint: DrRacket comes with a help system called Help Desk. 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.
Access the 2nd edition HtDP "universe" and "image" libraries in DrRacket. Put the following magic text at the top of your Definitions Window:
Libraries come with documentation. In the Help Desk, search for "universe". Also have a look at the documentation of the image library titled "2htdp/image".
Exercise 8: Download a tiny image off the Web and insert it into your Definitions Window. Use define to give it a descriptive name. Examples: cars, boats, planes, etc.
Hint: DrRacket comes with a help system called Help Desk. 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.
Exercise 11: Create an image that resembles the Indianapolis flag:
Exercise 12: Define a function which given a number, places a circle with that radius in the middle of a large empty scene.
Exercise 13: Use the function you just created, along with animate, to produce an animation.
Exercise 14: Create your own animation, using any functions that you want from the 2htdp/image library.