CS 1101: Lab 1

Lab Motivation and Goals

By the end of this lab, you should be able to:

Exercises: Getting to Know DrScheme (15 minutes)

Exercises: Practice with Conditionals (35 minutes)

A simple calculation of the risk of forest fires is based on the relative humidity and current wind speed. Fire risk is high if the relative humidity is 7% or lower and winds are greater than 20 mph. Fire risk is low if relative humidity is above 20% or winds are less than 5mph. In all other cases, fire risk is medium.

  1. Write a program fire-risk that consumes the relative humidity and current wind speed and produces a string indicating the fire risk (low, medium, or high).

  2. Write a program fire-risk->image that consumes the fire risk and produces an image of a bear with a colored circle illustrating the fire risk (red for high, yellow for medium, green for low).

    Start with the following bear image. To use the bear image in your program, right click on the image and save it to your computer. Follow the instructions on the using images page to load the bear image into DrScheme.

    The following image shows a possible output from (fire-risk->image 'low). You should not download this image -- your program should build something similar to this image.

    (Don't worry about getting the background colors just right -- on some machines, the bear background has come up grayish -- you do not need to match that background color.)

    If your solution looks complicated, consider whether you could have used additional smaller functions to compute the part of the answer that is different in each case.

    Everybody should be able to finish up to this point during lab. Finish all exercises that you don't finish during lab on your own time (we won't always ask you to do this, but the last problem illustrates a point about program design that you need to learn to think about).

  3. Write a program image->fire-risk that takes an image illustrating the fire risk and returns a string indicating the fire risk shown in the image. [HINT: use the image-inside? operator. Look it up in helpdesk if necessary.]

  4. In the first lecture, we talked about a program that searches for political bias in journalism. Part of that program involved seeing whether the labels "liberal" or "conservative" appeared near names of politicians known to be in each category.

    1. Write a function label-near? that takes a political label, a name and three words (all as strings) and produces a boolean indicating whether both the name and the label appear (in any order) within the three words.

    2. Write a function string-one-of? that takes a string of a word to look for and three strings of other words and produces a boolean indicating whether the first word is one of the three other given words. Then write label-near2? that has the same contract and purpose as label-near?, but is implemented using string-one-of?.

    3. Which of label-near? or label-near2? is preferable and why? What if we decided to expand the search to four adjacent words instead of three -- which program would you rather modify and why? What does this teach you about program design?