CS 330: Algorithms: Design & Practice

Homework8: Creating Abstractions
Due: In class on Tuesday, April 8, 2008


This assignment is about creating abstractions. The file statedata.txt contains mapping data about the states in the United States. The data is under development and is missing a small number of states, but is usable for this exercise. In this exercise, you will create Python abstract data type(s) to represent the state data. The format of the file is described below. The goal of the abstractions is to enable users to easily access all the relevant information about all the states in a uniform manner. You have to design the interface in a way that enables users to access all the data without worrying about the details of how the data is stored etc. You class abstractions should read the data automatically when an instance is created, or provide explicit input operations to do so.

This exercise requires you to use the concepts you learned in your earlier courses about designing and creating data abstractions and interfaces. So, take a good look at the data first, possibly write some test programs to understand the content of the data.

In the data file, each state is represented in two lines:

Line 1: <State name>,<state capital>,<x and y coordinates on the location of the state capital>
Line 2: x1,y1,x2,y2,...,xN,yN
where <x1,y1> are the starting coordinates of the polygon that makes up the state boundaries when you draw it. The coordinate system ranges from <0,0> ... <1500,1200>. For example, the data for Nevada is shown below:

Nevada,Carson City,132,426
147,336,218,351,290,367,258,532,245,563,233,558,230,593,122,434

That is, the coordinates of the state boundary are defined by the polygon <147,336>, <218,351>, <290,367>, <258,532>, <245,563>, <233,558>, <230,593>, <122,434>

Using this data, you can draw the map of the United States using the graphics.py module. This module is installed on all computers in the lab. Documentation for it is available by clicking here. Documentation is available here.

What to hand in:

1. A description of the design of your abstractions.
2. Examples of use.
3. The complete program listings along with any output.

Please ensure that these are nicely formatted and in readable form.


Back to CS330 Materials