CS 1101: Lab 2: Structs with applications in ecology

Lab Motivation and Goals

This lab is designed to help you practice

Background Information:

The well-being of animals strongly depends on the environment and changes in their surroundings often have noticeable effects on the animals. In this lab, you will use Scheme to study the effects that environmental changes may have on three types of bears: polar bears, grizzly bears, and black bears. You will do this by writing functions that simulate the effects based on gathered data. Polar bears inhabit arctic regions of the world, such as northern Canada. They are very large - adult males weigh an average of 1000 pounds - and their diet consists of things like seals, fish, and caribou. Grizzly bears are large like the polar bears, with adult males weighing between 800 and 1200 pounds on average. They also live in the north, many in Alaska and the northern parts of Asia. Their diet includes berries, fish, and moose. Grizzly bears can be Blonde, Brown or Black. Black bears are the smallest bears, with adult males weighing 300 to 400 pounds. These bears are unique to North America and many live all over the United States. They eat mostly vegetation, such as berries, but sometimes they also eat small animals like lemmings.

Exercises

  1. Create a separate data definition for each of the previously described bears. For Polar bears and Black bears you need to store its name, location, weight, and three elements of its diet. For Grizzly bears you need to store the same data as well as the color of the bear's fur. Now provide a data definition for bears in general. Location should be another struct containing the name of a place and the average summer temperature. Make sure you correctly identify the type of each data field when defining your structures.

  2. Write down all the operators and their contracts that Scheme automatically created for your definition of Grizzly bears from exercise 1.

  3. Write a template for functions over bears.

  4. Create examples of polar, grizzly, and black bears.

  5. In order to assess bears' diets, you would like to check if a given bear eats certain types of food. Write a function eats? which takes in a bear and a food, and returns true if the bear eats that food, false otherwise. HINT: Copy your bear template from #3 and work from there!

  6. In order to study bear behavior, you want to take several bears to live in a wildlife reserve in California. However, you do not currently have the facilities to support polar bears, so you only want to take grizzly and black bears. Unfortunately, the change in environment is very stressful for the bears and you've noticed that they drop an average of 10% of their weight because they do not eat at a normal rate. Write a function move-bear that takes in a bear and a location and changes the bear's location to the one given and changes the bear's weight if it is not a polar bear.
    ;;  move-bear: bear location -> bear
    ;;  Comsumes a bear and changes the bear's location and weight if it is not a Polar bear
    

    Everybody should be able to finish up to this point.

  7. Because of the number of animals at the animal reserve, there is a shortage of wild fish that certain bears need to survive, such as salmon. This is forcing you to buy farmed salmon, which, as recent studies have shown, may contain certain cancer-causing contaminants. Many of these contaminants are found in the layers of fat under salmon skin and you found a company that farms salmon with less fat, which they claim reduces the risk of disease.

    You want to study the effect that such a change in a bear's diet would have on the bear's weight.

    (a) Write a function change-diet that consumes a bear and replaces all instances of fish in its diet with "farmed fish". This change only applies to bears in the California wildlife reserve.

    (b) From observing bears in the wildlife reserve, you've noticed that since you made the switch to farmed salmon, bears who normally eat fish do not eat much of the salmon anymore. Instead, they rely mostly on other food sources from their diets. The wildlife reserve has many different types of berries, so bears who eat berries switch to relying mostly on this food source. The bears who previously relied on fish for food and now eat farmed salmon tend to lose 75 pounds due to this change. However, bears who did not eat fish in the first place benefit from the new surroundings and gain an average of 50 pounds. Write a function change-weight that takes in a bear and increases or decreases its weight appropriately. If the bear's weight is not affected, it should stay the same.

    (c) Write several test cases for your function above that illustrate the effects of moving bears to the California wildlife reserve where they can only eat farmed salmon.


You should turnin your lab under the name lab2-ecology.rkt.