EECS 111: Homework 1

Due: Tuesday, April 16 at 11:59 PM

Please note: This assignment is to be completed with your assigned partner

Purpose

The goal of this problem set is for you to gain practice 1) expressing mathematical relationships between values as BSL functions, 2) using conditional expressions, enumerations, and intervals, and 3) communicating your designs to others.

Design & Code Style

Design and code style are both essential to effective programming, and thus each will be graded. For design, we expect you to follow the six-step Design Recipe presented in HtDP/2e, §3.1. For style, it means that:

Problems

  1. Consider the formulas that you derived for problems 1, 2, and 3 of Homework 0. Formulate each of these as a BSL function. (Be sure to follow the Design Recipe. This means that each function has a signature, a purpose statement, descriptive name, at least 2 examples, and complete test coverage.)

  2. Write a data definition for the filling choices given in problem 4 of Homework 0, and write another data definition for the choice of sauces.

    Bonus: Can you design a data definition to represent all possible ravioli orders with one choice of filling and one choice of sauce? For example, you should be able to represent the information butternut squash ravioli with cream sauce.. A String is not a suitable representation.

  3. Consider this data definition:

    ; An Orientation is one of:
    ; - "portait"
    ; - "landscape"
    ; - "square"
    

    We consider the orientation of an image to be "portrait" if its height exceeds its width, "landscape" if its width exceeds its height, or "square" if its height and width are equal. Design a function classify-image that, given an Image, returns its Orientation.

  4. Design a function string-prefix that takes a number n and a string s and produces a string containing the first n characters of s. (Hint: Use function composition.)

  5. At the end of EECS 111, your instructor will compute a numeric grade in the range 0 to 100, inclusive, for each student, and then convert that number to a letter grade. Suppose that the letter grade comes from this data definition:

    ; A Letter-grade is one of:
    ; - "A"
    ; - "B"
    ; - "C"
    ; - "D"
    ; - "F"
    

    Suppose, further, that your instructor will give an A for numeric grades of 93 and above, B for grades from 85 up to but not including 93, C for [65, 85), D for [50, 65), and F for less than 50.

    1. Formulate a more precise data definition than Number to specify the possibilities for numeric grades. Use intervals as in the definition of WorldState for the UFO exercise.

    2. Design a function to convert numeric grades to letter grades.

  6. HTDP/2e, Exercise 47; except that:

    • the maximum happiness level is fixed at 100 instead of being passed as an argument to gauge-prog, and
    • gauge-prog : World -> World takes the initial happiness level as its parameter and passes that on to big-bang.

Evaluation

Your code will be evaluated for:

  1. design (how carefully your programming process has followed the Design Recipe),
  2. correctness (how closely your code’s behavior matches its specification, which is this web page),
  3. test coverage (whether every expression in every function—except for gauge-prog—is checked by some automated test, as with check-expect or check-within), and
  4. style (how readable it is, as measured by the rules listed above).

Turn In

Please write all your code in one .rkt file and submit it through Canvas.