Starting from:
$30

$24

Lab 1 The Basics

Purpose: The purpose of this lab is to get you set up on the handin server and to give you some hands-on experience with the BSL programming language and with the DrRacket programming environment for BSL. The second purpose is to pair you up with a partner.
Textbook references: Preface (DrRacket and the Teaching Languages), Prologue: How To Program, Chapter 1: Arithmetic, Chapter 2: Functions and Programs
Introduction & Setup
Exercise 1 Follow the instructions on this page to set up an account on the handin server. You will be using the handin server to submit all your homeworks for the semester.
Exercise 2 Read the course contract and sign it on the handin server.
Exercise 3 Fill out the exam conflicts assignment on the handin server. You MUST fill this out even if you don’t have any conflicts with either of the midterm exams. Please check your class schedule before filling it out so that you have the most accurate information possible.
Exercise 4 Download and install DrRacket on your machine.
Partners
Goals Partnering.
In this course you will be completing your assignments with a partner. Because we are not seated physically together in a lab, your partner will be assigned randomly. You will work with this partner on your labs and homeworks. You should have one computer for the two of you: one person should be doing the typing, but both partners should be contributing ideas and code. You should switch roles regularly, to let both partners work equally. The two of you will get one grade for any given assignment.
Exercise 5 Make sure you are registered on the handin server. Once everyone is registered, your TA will randomly create teams.
Exercise 6 On the handin server, on the course homepage, you should now see that you are in a team, whose name looks something like "Team 12345 – Amal Ahmed and Ben Lerner". Next to that team name, you’ll see an @ link, which will let you email everyone in the team (which in this case is just you and your partner). Exchange contact information with your partner: telephone number, latest-greatest social network scheme, whatever-app.
Exercise 7 In Microsoft Teams, create a channel whose name is exactly the same as your team on the handin server, i.e. "Team 12345 – Amal Ahmed and Ben Lerner".
Exercise 8 Agree to a first meeting time and medium to start working on Homework 1 with your partner. It’s due on Friday so you are going to have to do it soon. It would be a good idea to establish a time and medium to work on future homeworks as well, if you can.
Exercise 9 Read the bottom of the policy page to find out what to do if you are having problems with your partner. It is very important that you tell us if you are struggling to work with your partner. Otherwise we can’t help you resolve the problem.
How Labs Operate
Although your TA went over this in the introduction, you might find it helpful to find this written down. Lab writeups consist of three major parts: starter code, reviewed exercises, and exercises.
    • Starter Code comes with a brief explanation you are expected to read and understand, and will enable you to complete the following exercises. You should always copy and paste the starter code into your program. Unless otherwise specified, you should make sure to take the time to understand the code you are copy/pasting.
    • Reviewed Exercises are exercises we expect you to complete on your own, but the head TA will go over them together as a class. All labs will start with a reviewed exercise, and some have reviewed exercises in the middle, which the head TA will go over once they get a sense that most of the lab has gotten a chance to try the exercises on their own.
    • Exercises are exercises you will complete on your own that the head TA will only review with the whole lab if they feel the majority of people are having difficulty with the problem.
The TA will go over the reviewed exercises in a meeting in the General channel of your lab Team. When this review is complete, you will break up into smaller groups. Each of the tutors and TAs will start their own meeting in the channel with their name on it, and approximately seven pairs of partners should join each tutor’s meeting. Your head TA will assign you to work in a specific channel. You should use the assigned channel to ask the staff member if you get stuck, but you should try to complete the lab in your team-specific channel.
Note: this lab protocol is experimental, and we may revise it to make labs more fun and interactive and effective as the semester continues.
Each lab has a Before You Go... section, with a brief note. It is our hope you complete the lab up to this point before the lab time runs out. Most labs continue on past this, though, and there are some fun and exciting problems at the end of each lab.
You are free to leave when you have completed the entire lab or the head TA ends lab when time is up.
Using DrRacket
Goals: Interact with Dr. Racket’s definitions window, interactions window, and stepper. Create basic expressions and function definitions. Introduce different types of errors.
Exercise (Reviewed) 10 Define a function multiple-of-5? that accepts a number and determines if it is a multiple 5.
Exercise (Reviewed) 11 Define a constant GREETING which contains your greeting. Then, use it in a function that takes a name and outputs a full greeting.
Exercise 12 Call these functions in the interactions window. What happens if you call (multiple-of-5? "cat") or (greet #t)?
Exercise 13 Run the stepper on your program. Follow it through to see how it evaluates the tests.
Exercise 14 Below is a piece of code that will run and all the tests will pass... but is it correct? Hold a brief philosophical discussion about the importance of language and naming in programming with yourself, labmates, and/or course staff to arrive at the answer.
; times-itself : Number -> Number
; Multiply a number by itself
(check-expect (times-itself 0) 0)
(check-expect (times-itself 2) 4)
(define (times-itself n)
  (+ n n))
Exercise 15 After determining this is indeed incorrect, what could the author of this code have done to catch their mistake?
Exercise 16 It has been estimated that fixing the water in Flint, Michigan would cost 55 million dollars. Given someone’s net worth, define a function that will determine what percentage of their net worth it would take to fix the water. Elon Musk’s net worth, for example, is 19.7 billion and Jeff Bezos’ is 140.9 billion.
Conditions
Goals: Get practice writing conditional functions.
Exercise (Reviewed) 17 Define the function absolute which consumes a number and produces the absolute value of that number (do not use abs).
Starter Code: Below is a data definition that defines what a Score can be.
; A Score is a number in the range [0, 100]                     
Exercise 18 Define the function letter-grade. It consumes a Score and produces the corresponding letter grade ("A", "B", "C", "D", or "F"). You may be as wishful as desired in choosing your own grading scale.
Exercise 19 Define a function that given a number of hours worked an an hourly wage computes how much money has been earned. Any hours worked over 40 hours must be paid at 1.5 times the given rate.
Exercise 20 Define the function runtime that given a movie title outputs its runtime in minutes. Ensure the function works on a handful of inputs, and for others throws an error, which can be tested with check-error.
Programming with Images
Goals: Get practice programming with images and writing a simple animation.
Starter Code: This line of code is required to program with images.
(require 2htdp/image)
Exercise 21 Use triangle, square, rectangle, above, and overlay/align to draw yourself a house with a roof and door (and circle if you’re feeling bold enough for a door handle).
Exercise 22 Congratulations, you’ve moved up a tax bracket. Define a constant WINDOW and place two of them on your humble home. Note how in using a constant we only have to draw it once and get to use it twice!
Exercise 23 Define a function scene that takes in a natural number and places a circle of that radius at the center of a 50x50 empty-scene. Use modulo to ensure the radius always stays below 20.
Starter Code: These lines of code will run your animation.
(require 2htdp/universe)
(animate scene)
Exercise 24 Launch your animation by pressing run.
Before You Go...
Make sure you can log into the handin server and sign the course contract if you didn’t already do that. Also, you should submit whatever code you and your partner finished today to the "Lab 1 - sample homework" assignment. You should only submit one file per team (where the team is you and your new homework partner). This is how you will submit homeworks throughout the semester. If you have any questions regarding the lab or the course please feel free to ask a TA or tutor.
Pixar Whomst?
Goals: Use math (gasp) and conditional programming to make the animation better.
Exercise 25 Use cond (or if if you’re feeling cheeky) to make the circle grow and shrink in a loop instead of grow and suddenly dissapear and grow again. Since computing the radius is now a somewhat complex computation, it makes sense to write a seperate helper function which only computes the radius that scene calls. Hint: quotient, even?.

More products