On this page:
Introduction (10 minutes)
Using Dr  Racket (10 minutes)
Submitting Homework (10 minutes)
Conditions (35 minutes)
Programming with Images (35 minutes)
Before You Go...
6.7

Lab 1 The Basics

home work!

Purpose: The purpose of this lab is to give you some hands-on experience with the BSL programming language and with the DrRacket programming environment for BSL.

Textbook references: Preface (DrRacket and the Teaching Languages), Prologue: How To Program, Chapter 1: Arithmetic, Chapter 2: Functions and Programs (up to but not including 2.5)

Introduction (10 minutes)

Goals: Read and sign the course contract. Find a partner and exchange contact information.

Exercise 1 Read and sign the course contract.

Exercise 2 Find a partner to work with in the lab and on homeworks (the person next to you for instance). Exchange contact information with your partner so that you can meet up outside of the lab.

Using DrRacket (10 minutes)

Goals: Interact with Dr. Racket’s definitions window, interactions window, and stepper. Create basic expressions and function definitions. Introduce different types of errors. Use F1 to find documentation of functions and keywords.

Sample Problem Define a function that accepts a number of minutes and computes how many whole hours these minutes represent.

(define (minutes->hours num-minutes)
  (/ num-minutes 60))

Sample Problem Define the function how-far which consumes the number of minutes you drive at 55mph and produces how far you get in the given time.

(define SPEED 55)
(define (how-far num-minutes)
  (* (minutes->hours num-minutes) SPEED))

Submitting Homework (10 minutes)

Exercise 3 Download the handin client by opening DrRacket and going to File > Install Package and typing neu-cs2500-handin. Then click the "Install" button. This may take a few moments to run. When it is finished you should no longer see an option to abort the installation. Restart DrRacket and you should see a button in the top right of DrRacket that says "CS2500 Handin". Should this fail you can install the server by going to File > Install PLT file and typing in http://www.ccs.neu.edu/course/cs2500/cs2500-f16-client.plt and then clicking the "Install" button.

Exercise 4 Complete at least ONE of the graded exercises in Problem Set 2B. Try submitting this by clicking the hand in button at the top right corner of DrRacket. In order to submit you must enter both your username and password AND your partner’s username and password. If you run into an error message, raise your hand and a tutor or TA will come around to help you.

Exercise 5 Check to make sure you submitted correctly. Go to the handin web client and log in using your username and password (only one of you needs to log in). You should see a "handin.rkt" file in the row for the assignment you submitted to.

Conditions (35 minutes)

Sample Problem Define the function how-hot which consumes a temperature and produces one of three strings: "cold" for temperatures below 45 (inclusive), "comfortable" for temperatures between 45 (exclusive) and 75 (inclusive), and "hot" for temperatures above 75.

(define (how-hot temp)
  (cond [(<= temp 45) "cold"]
        [(<= temp 75) "comfortable"]
        [else "hot"]))

Sample Problem Define the function absolute which consumes a number and produces the absolute value of that number.

(define (absolute n)
  (cond [(< n 0) (- n)]
        [else n]))

Exercise 6 Define the function letter-grade. It consumes a score (number) between 0 and 100 and produces the corresponding letter grade ("A", "B", "C", "D", or "F"). You may choose your own grading scale.

Exercise 7 Define the function how-long which consumes a Number representing how long (in minutes) you have to wait for something and produces a String which represents how you feel about waiting this long. If the number is less than or equal to 10 it should produce "great!". If the number is greater than 10 but less than or equal to 60 it should produce "okay". If the number is greater than 60 it should produce "not good".

Exercise 8 Define the function good-weather? which consumes a String representing the current weather and produces a Boolean which is true if the weather is good and false otherwise. You may determine what good weather means to you (for example my function would return true if the string was "sunny" or "blizzard" but some people would argue that a blizzard is not good weather).

Exercise 9 Define a function that consumes a String and judges how long it is. If the string is shorter than 3 characters, we call it stubby. If it is up to 10 characters, it’s a shorty. For strings, up to 25 characters, we go with middling. And for a string that’s even longer, the function says it is "too wordy".

Programming with Images (35 minutes)

Sample Problem Define the function red-frame, which consumes an image and draws a red frame around it.

(define (red-frame img)
  (overlay img (rectangle (+ 1 (image-width img))
                          (+ 1 (image-height img))
                          "solid" "white")
           (rectangle (+ 4 (image-width img))
                      (+ 4 (image-height img))
                      "solid" "red")))

Exercise 10 Define the function sale. It accepts a wish in the form of a String and, if it recognizes the string, it returns an image of this object; otherwise it produces "sorry" as a large image of the text. You may decide which wishes to accept. You can use images from the web or build the images yourself using circles, squares, and other shapes that you can draw in Dr. Racket.

Exercise 11 Define the function draw-sheep. It accepts a Number, representing the x-coordinate of the sheep and draws a sheep onto a green field at that x coordinate. You may place the sheep at whichever y-coordinate you like.

Exercise 12 Define the function on-top which takes two Images and overlays one on the other such that the tops of the images line up.

Before You Go...

Make sure you exchange contact information with your lab partner, as you will be working together on problem sets and in labs in the future. If you have any questions regarding the lab or the course please feel free to ask a TA or tutor.