CS 2102 - Dterm 10

Homework 1 - Review - Designing Programs with the Design Recipe

Due: Tuesday, March 23 at 5pm


This assignment is to be done individually.

Acknowledgement

This assignment is based on an assignment designed by Dr. Viera Proulx.

Assignment Goals


Problems

Note: All problem solutions should be coded in DrScheme. Use the check-expect or check-within format of the testing.ss teachpack to define your test cases.

  1. A database of information about localities in the USA gives us the locality's zip code, the name of the locality, the state in which it is located, and the latitude and longitude for the locality. Design the data to represent a city in the USA that contains this information.

    When designing your data, note that there may be several different entries for a given city; for example, a city like Worcester has several different zip codes which represent localities at slightly different latitude and longitude coordinates.

    Use a separate data definition to represent the location of each locality.

    You may use data from a list of US state capitals when creating examples of data. (You do not have to use all the data in this file - we may be using all the data in a later assignment.) Note that the data lists the longitude before the latitude.

  2. Suppose we were to draw localities on a map of the USA (we'll only consider drawing localities that reside in the lower 48 contiguous United States). Assume our Canvas is 100 pixels wide and 100 pixels tall. We want to convert the latitude and longitude representation of the location into a posn* on our map**.

    Assume that the latitude and longitude lines are parallel to the Canvas boundaries (parallel projection). Assume that

    Define the function to-posn that produces a posn that represents the given location on our Canvas.

    *A posn is a struct that is built-in to DrScheme, and is used to represent x and y coordinates. It is defined as:

    ;; a posn is a struct
    ;; (make-posn number number)
    (define-struct posn(x y))
    

    **The origin of the Canvas (x=0, y=0) is the upper-left corner.

  3. Define the function distance that computes the distance (in miles) between two cities. Estimates tell us that one degree of longitude (at our latitude) is approximately 55 miles and one degree of latitude is approximately 70 miles.

  4. Define the function total-distance that computes the length of a trip on which we visit all cities in a list of cities in the order in which they appear in the list.

    You should first design this function using the Design Recipe. After you have tested the function and you're convinced it works, modify your function to solve the problem using accumulator style. (Hand in only the accumulator style function.)

  5. Define the function all-states that produces a list of all states we visit when our trip takes us to all cities in a given list of cities. Make sure each state appears in the list only once.

What to Turn In

Using web-based turnin, turn in a single file containing all code and documentation for this assignment. Name your file username-hw1.ss, where username is your CCC username. Your name and CCC username should appear in a comment at the top of the file.