6.10

Assignment 1

home work!

Programming Language BSL

Due Date Tues 1/16 at 9:00pm

Possible Points 1

Purpose To practice submitting a file and writing some basic functions and a simple world program.

For this assignment and all future assignments you must upload a .rkt file in the specified language at the top of the assignment. Failure to do so will result in a 0. No exceptions. This will also be the last individual assignment of the semester. Future assignments will be submitted with lab partners (to be assigned on Friday, 1/12, in lab).

Finger Exercises You are not required to submit your finger exercises but they will be helpful so we recommend doing them anyway.

Exercise 1 Write a function that subtracts 2 from a number.

Exercise 2 The following table describes how far a person has gone in a race in a certain amount of seconds:

t =

  

1

  

2

  

3

  

4

  

5

  

6

  

7

  

8

  

9

  

10

d =

  

3

  

4.5

  

6.0

  

7.5

  

9.0

  

10.5

  

12.0

  

13.5

  

?

  

?

Write a function that predicts, based on this data, how far they will have run at time t. Write three check-expects: two that test to see the data in the table matches your function’s output, and then one more that tests the output when t is at least 9.

Exercise 3 Take a look at figure 1, which is a graph of f, a function of x.

Turn the graph into a table for x = 0, 1, 2 and 3 and formulate a function definition.

image

Figure 1: A function graph for f

Graded Exercises

Exercise 4 Complete the following table:

t =

  

1

  

2

  

3

  

4

  

5

  

6

d =

  

QWERT

  

QWER

  

QWE

  

QW

  

?

  

?

Turn this table into a function definition. The function takes natural numbers and produces strings. A natural number is 0, 1, 2, 3, 4, 5, etc.

Exercise 5 Develop the function qwerty. The function consumes a natural number and extracts that many keyboard characters from the string "qwerty".

What happens when the function is applied to 13? In that case, qwerty produces just the string "qwerty". The same happens for all other numbers that are too large.

Exercise 6 In case you forgot your grade school terminology, a counting number is 0, 1, 2, 3, 4, 5, ... We will get to the "..." part in a few weeks. Design the function ticket. It consumes two counting numbers: one that represents the speed of a car and the other one the speed limit of the road. The result is one of these strings: (1) "fine" for a car that goes below the speed limit; (2) "danger" for a car that is going at most 5 mph faster than the speed limit; or (3) "ticket!" for a car that exceeds that last speed.

Challenge Instead of issuing "ticket!" for the last case, make the function create the string "you drove ___ mph" where the underlines are replaced by the car’s speed.

Exercise 7 Use the big-bang expression to develop a program that "grows" the image of “Hello World” using the text function on a 500 x 300 canvas. The image should be placed in the center of the canvas. Start the text size at 1 and stop growing when the size reaches 80. You will need a function that draws the text on the scene and a function that represents how the text will look after one "tick."

Add a function that returns the text to size 1 when the mouse is clicked anywhere in the canvas. You can read about mouse events in DrRacket’s Help Desk — the on-mouse clause of big-bang is a good place to start.