Problem Set 2

home work!

Programming Language BSL

Purpose The purpose of this problem set is to practice developing simple and conditional functions. The functions deal with atomic forms of data (numbers, symbols, booleans, images) and intervals.

Finger Exercises HtDP/2e: 13, 18, 19, 20, 21, 32, 33, 34, 61, 64

Solutions must be submitted to Blackboard by 7:00pm on Tuesday, January 27th.

The solutions to all of the following problems should be contained in one .rkt file. Include a signature, purpose statement and tests for each function that you develop. Late homework is not accepted

image

Problem 1 The Center for Disease Control collects information on patient visits to health care providers for influenza-like illness (ILI) to estimate the level of flu activity.

The percentage of patient visits to healthcare providers for ILI reported each week is weighted on the basis of state population. This percentage is compared each week with the national baseline of 2.4%. The baseline is the mean percentage of patient visits for ILI during non-influenza weeks for the previous three seasons plus two standard deviations.

The activity levels correspond to the number of standard deviations away from the mean the percent of visits due to ILI is each week. There are 10 activity levels classified as minimal (levels 1-3), low (levels 4-5), moderate (levels 6-7), and high (levels 8-10). An activity level of 1 corresponds to values that are below the mean, level 2 corresponds to an ILI percentage less than 1 standard deviation above the mean, level 3 corresponds to ILI more than 1, but less than 2 standard deviations above the mean, and so on, with an activity level of 10 corresponding to ILI 8 or more standard deviations above the mean.

Develop a program called flu-activity that consumes a flu activity level and produces its classification.

For instance (flu-activity 6) produces “moderate”

Problem 2 Mathematical equations in one variable are claims about an unknown number. For example, the quadratic equation x2 + 2x + 1 = 0 is a claim concerning some unknown number x.

For x = -1, the claim holds: (-1)2 + 2(-1) + 1 = 1 – 2 + 1 = 0

For x = 1, the claim doesn’t hold because: (1)2 + 2(1) + 1 = 4, not zero.

We can use BSL to formulate equational conditions as a function and use the function to test whether the proposed solution is, in fact, a solution.

Translate the following equations into BSL functions that determine whether it is true or not that a given number is a solution:

You should test for numbers that are solutions and numbers that are not.

Problem 3 Translate the following intervals on the real line into BSL functions that accept a number and return true if the number is in the interval and false if it is outside.

  • The interval [4, 16)

  • The union of the intervals (20, 30) and (40, 50)

  • The range of numbers outside of the interval [40, 60]

Problem 4
  • > (require 2htdp/image)
    > (text "Hello" 24 "olive")

    image

    The text function provided from 2htdp/image constructs an image that draws the given string, using the font size and color as shown above.

    Develop a program that "grows" the image of “Hello World” using the text function on a 500 x 300 canvas. The image should be placed in the center of the canvas. Start the text size at 1 and stop growing when the size reaches 80.

  • Add a function that returns the text to size 1 when the mouse is clicked anywhere in the canvas. You can read about mouse events in DrRacket’s Help Desk—the on-mouse clause of big-bang is a good place to start.