Problem Set 3

home work!

Programming Language BSL

Purpose The purpose of this problem set is to practice with data definitions.

Finger Exercises HtDP/2e: 30, 31; 61, 64, 68, 71

image

Problem 1 Data Definitions

The four Ninja Turtles are Leonardo, Michaelangelo, Raphael, and Donatello. Write a data defintion for a Ninja Turtle. What is the template for a Ninja Turtle?

A percentage is a real number between 0 and 100. Write a data definition for percentage.

Problem 2 HtDP/2e: Exercise 60. Include test cases for the values of the constants you define.

Problem 3 HtDP/2e: Exercise 66. Include signature, purpose statement, and test cases.

Problem 4 Define a function that translates a blue object closer to a red object on a 200 x 200 plane. Specifically, the main function consumes two Posns, one called red and blue. It produces an image that contains:
  1. a blue dot

  2. a red dot

  3. a black line between the blue and the red dots

  4. a green dot on this line, 10% of the way along the line from the blue dot to the red dot. (Or, alternately, 90% of the way along the line in the reverse direction, from red to blue.)

Here is a sample output:

image

Domain Knowledge (Geometry) To find the green point between the red and the blue one, cut the "distance" in each dimension to 90% and add the results to the respective coordinates of the red point.