Teaching
2500 F '11
 
Assignments
The Hand In
Set 1
Set 2
Set 3
Set 3h
Set 4
Set 4h
Set 5
Set 5h
Set 6
Set 7
Set 6h
Set 8
Set 7h
Set 9
Set 8h
Set 10
Set 9h
Set 11
Set 10h
Set 12

Problem Set 5h

Due date: 10/12 @ 11:59pm


Honors-section homework (Due date pushed back to Wednesday since it went up late.)

HtDP Problems

10.1.5, 10.1.6, 10.1.7, 10.1.8

Graphical Editor, Revisited

Re-develop your graphical editor from the last assignment using a slightly different data representation.

A 1String is a string, s, whose length is exactly one, i.e. (= (string-length s) 1). Note: 1String is not a valid BSL identifier, but it works fine as a name for your data representation.

A list of 1Strings (Lo1String) is one of:

  • empty
  • (cons 1String Lo1String)

Revise the Editor data defintion from the first part of the last assignment to only use 1Strings and Lo1Strings:

  (define-struct editor (pre post))
  ;; An Editor is a (make-editor Lo1String Lo1String)

Re-develop the editor program using this new definition (Exercise 1-5).

Exercise 6: Discuss the design trade-off in a paragraph of 20 to 30 words. (We will deduct points for each word in excess of 30.)

Pocket Calculator

In this part of the assignment you will develop the basic pieces of a small pocket calculator for arithmetic expressions.

An arithmetic expression can either be a number, a variable, a unary operation applied to one argument, or a binary operation applied to two arguments. So for example, 3 + 4 is an arithmetic expression -- the binary operation + is applied to the arithmetic expressions 3 and 4. Arithmetic expressions nest of course, and we use parenthesis to indicate the nesting, so for example, (1 / 2) * (x + (3 + 4)) is an arithmetic expression. The basic operations are (unary) -, which flips the sign of its argument, and (binary) -, +, *, /, which perform subtraction, addition, multiplication, and division, respectively.

Exercise 7: Develop a data definition for arithmetic expressions without variables.

Exercise 8: An expression that contains no variables can be evaluated. For example, 3 + 4 evaluates to 7. Develop a program eval-arith that evaluates a given arithmetic expression (without variables).

Exercise 9: Develop a data definition for arithmetic expressions that may contain variables. Hint: what can you reuse?

Exercise 10: Develop a program plug-in that consumes an arithmetic expression (that may contain variables), a variable, and a number, and produces a similar arithmetic expression where all occurrences of the given variable are replaced with the given number. So for example, plugging 5 in for x in (the representation of) 2 * (x * x) should produce the expression (that represents) 2 * (5 * 5).


last updated on Tue Nov 29 19:02:43 EST 2011generated with Racket