CS2500: Problem Set 2

Due: Tuesday, January 26 at 11:59 PM

Please Note: This assignment is to be completed with your partner

Purpose

The goal of this problem set is to express mathematical relationships between values as BSL functions, and to begin using conditional expressions, enumerations, and intervals.

Problems

  1. Consider the formulas that you derived for problems 1, 2, and 3 of Problem Set 1. Formulate each of these as a BSL function. (Be sure to follow the design recipe. In particular, each function must have a contract, purpose, and at least 2 tests.)

  2. Write a data definition for the ravioli choices given in problem 4 of Problem Set 1, and write another data definition for the choice of sauces.

    Bonus: Can you design a data definition to represent all possible orders of one ravioli filling with one 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. HTDP/2e, Exercise 39

  5. At the end of CS2500, 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 from this data definition:

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

    Suppose your instructor will give an A for numeric grades of 90 and above, B for grades from 80 up to but not including 90, C for [70, 80), D for [60, 70), and F for [0, 60).

    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 example.

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

  6. HTDP/2e, Exercise 49

Turn In

Please follow the electronic homework submissions instructions.


CS2500 Home

Last updated 21 January 2010.

Valid XHTML 1.1 Valid CSS!