CS 1101 - Aterm 12
Homework 3 - Unions and Simple List Processing
Due: Tuesday, September 11 at 5pm
Read the expectations on homework.
Assignment Goals
- To make sure you can define unions and write programs over unions
- To make sure you can define simple lists and write programs over lists
The Assignment
Writing Data Definitions for Unions
Hurricane Isaac wreaked havoc on the Gulf Coast of Louisiana last week. The country's midsection has been plagued by drought throughout the summer. In this
assignment, you will create data definitions for various kinds of
weather-related phenomena, and write programs over those data definitions.
A storm can be any one of the following:
- hurricane Information required for a hurricane consists of the
name of the hurricane, the category (a number between 1 and 5, inclusive),
the maximum sustained winds in miles per hour, the velocity of the storm in
miles per hour, and the storm's heading (for example, NNW).
- tornado The information required for a tornado consists of the
latitude and longitude of the location where the tornado touched down,
the severity of the tornado (using the Fujita index), the velocity of the
tornado, and its heading. The possible values for
the Fujita index are F0, F1, F2, F3, F4, and F5. The latitude and longitude
can be represented in this assignment as whole numbers (0 - 90 for latitude, 0 - 180 for longitude) followed by a designation of north or south, east or west (so, for example, Worcester is at 42 N, 71 W).
- thunderstorm The definition of a thunderstorm consists of the
number of inches of rainfall, the maximum wind gust in miles per hour, the
velocity of the storm in miles per hour, and its heading.
Writing Programs for Unions
- Develop a data definition for each type of
storm described above, and one for storms in general.
Provide at least one example for each kind of storm.
- Provide the template for each data definition you made in Problem 1.
- Write a function
fast-moving-storm?
that consumes a storm
and produces a boolean. The function returns true if the velocity of the
storm exceeds 30 mph, otherwise it returns false.
-
Write a function
warning
that consumes a storm and
produces a string. The string that is produced is as follows:
- "stay inside" if the storm is a thunderstorm with maximum wind gusts
less than or equal to 30 mph
- "seek shelter" if the storm is a thunderstorm with maximum wind gusts
in excess of 30 mph, if the storm is a tornado, or if the storm is a
hurricane of category 1, 2, or 3
- "evacuate" if the storm is a hurricane of category 4 or 5
- Write a function
upgrade-category
that consumes a storm and
produces a storm. The storm is returned
unchanged if the given storm is a thunderstorm, a tornado of severity F5, or a hurricane of category 5. Otherwise, the storm that's produced is a storm
the same as the original, except that the severity or category of the new storm
is at the next higher level.
Writing Programs for Simple Lists
- Write the data definition for a list-of-string. Provide examples of list-of-string.
- Write the template for functions over a list-of-string
- Write a function
character-count
that consumes a list-of-string
and
counts the total number of
characters in all strings in the list.
- Write a function
all-alphabetic?
that consumes a list-of-string and produces true if all characters in all strings in the list are alphabetic
characters. Otherwise, the function produces false. (Hint: check the DrRacket
help desk for the function string-alphabetic?
)
What to Turn In
Here is the grading sheet that the graders will be using for Homework 3.
Using web-based turnin,
turn in a single file containing
all code and documentation for this assignment. Name your file according to the naming conventions for files.
Make sure both partners' names and login names appear at the top of the file in a comment.