CS 5010 F '09
Pair Programming
The Recipes
The Style
Set 1
Set 2
Set 3
Set 4
Set 5
Set 6
Set 7
Set 8
Set 9
Set 10
Set 11
Set 12

Problem Set 1


Due date: 9/23


The goal of this problem set is to help you design domain-specific functions, functions that deal with enumerations and unions, functions that deal with structs, and functions that have it all.


HtDP: 4.2.1, 4.4.1, 5.1.2, 6.3.1, 6.4.1, 6.5.1, 7.2.1, 7.2.2

Required Problems:

Note 1: You must use DrScheme's HtDP Beginning Student Language (BSL) and the Universe teachpack to solve the problems.

Note 2: Changes to "constants" in your solutions should have no side effects on the workings of your program (especially your test cases).

  1. A rocket accelerates at 5 meters per square-clock tick like this:

    after t = 0 1 2 3 4 ... 10 ... 15 clock ticks
    the rocket's y coordinate 0.0 2.5 10.0 22.5 40.0 ... ?? ... ?? pixels

    Your first task is to design the function yy, which, given a number of clock ticks, computes the y coordinate of the rocket.

    Your second task is to create the image of a rocket using the primitive operations of BSL. Keep it simple!

    Your third task is to design the function to-image, which, given a number of clock ticks, creates a scene of the rocket whose center point has gotten as many pixels from the bottom border as yy dictates. As far as the x coordinate is concerned, keep the rocket exactly in the middle.

    Hint: You should tabulate the first few elements of to-image just like we tabulated the first few elements of yy for you. Paper and pencil is enough; no need to turn in this table.

  2. Design a Universe program that graphically illustrates a finite-state machine for accepting strings of the shape "a" followed by an arbitrary number of "b" and "c" followed by "d" over the alphabet of 26 lowercase letters in the English alphabet. Your program should discard all key events of length greater than 1.

    The initial state should be a 100 by 100 white rectangle. Once your program has seen an "a", it should display a 100 x 100 yellow rectangle. It sticks with yellow until a "d" is entered, at which point it switches the color of the rectangle to green and stops to work. If at any point some unacceptable letter is entered, the program should display a red rectangle of 100 by 100 pixels and go into a final state, too.

  3. Here is a data definition for the class of all Exprs, plus the necessary structure definitions:
         (define-struct pls (x y))
         (define-struct mul (x y))
         ;; Expr is one of: 
         ;; -- (make-pls Number Number)
         ;; -- (make-mul Number Number)
         ;; interp. a pls struct represents an addition,
         ;; and a mul struct represents a multiplication 

    Design a program that renders an Exprs as an image. The main function must consume an Expr and a boolean flag. It produces an image of the given Expr; the boolean flag determines whether the Expr should be rendered as a prefix expression or an infix expression.

    Domain knowledge: Use parentheses to surround the rendered Exprs, no matter whether they are in prefix or infix notation. The operator should be separated from operands by one "string space", and the operands should be separated from other operands or the operator via such a space. There is no need to separate the parentheses from either the operands to operators. All text is rendered as 11pt and black.

  4. Project: Design a world program that acts as a one-line editor. The program should allow you and even your grandmother to enter and edit one line of text. Editing means changing existing text, perhaps by deleting a character or by adding another one to the end of the existing text, in the middle, or even the beginning. Your grandmother should also be able to navigate the text via arrow keys.

    The project is explained in detail in HtDP/2e (Chapter: Adding Structure).

last updated on Wed Dec 2 17:58:10 EST 2009generated with PLT Scheme