>
CS 1323 Honors, Fall 1996

Individual Project 5

Data Entry

Due Wednesday, October 16, 4:30pm

What to Hand In (see also: example project solution)

Project 5A

Write a program that prompts for a city, state, and zipcode to be entered from the keyboard, then displays it on the screen in standard form.

The city/state/zip may be entered in one of several forms:

standard
city, two-letter-state-code zipcode
Example:
Rapid City, SD 57701
long
city, state zipcode
Example:
Rapid City, South Dakota 57701

These forms, along with their variations described below, are the only forms of data your program is required to deal with.

The comma between the city and state portions may be missing.

The state portion, for certain states, may be abbreviated by the first few letters of the state name. You may choose which of such abbreviations your program will handle, but it must handle, at least, Cal and Calif for Calfornia, Colo for Colorado, O for Ohio, and Okla for Oklahoma.

States with directions (North, South, West) in their names may have the direction abbreviated by its first letter.

Any abbreviation, including two-letter state codes, may or may not be terminated by a period. A comma between the city and state and/or between the state and zipcode may or may not be present. The zipcode may be missing. Names and abbreviations may be all capital letters, all lower case, or any combination (for example, OK, Ok, ok, and oK are all equivalent entries for the Oklahoma state code).

Regardless of the form in which the city/state/zip is entered, it must be displayed in standard form and with first letters (only) of cities capitalized and both letters of two-letter state codes in all caps.

Include a function in your program that converts from a string containing a city/state/zip in any of the allowed entry forms to a tuple of type (String, String, String) in which the first component is the city, the second the two-letter state code, and the third the zipcode. This will be known as a city-tuple.

Include another function that converts from a city-tuple to a string containing the city, state, and zipcode in standard form. Use both functions profitably in your program.

Package the conversion functions in a module called CityEntry. Import these functions into your main module, where the input/output commands reside.

The file UnitedStates.lhs, available under Supplied Software on the CS1323h Web site, contains a module that defines a sequence of strings naming the states and another that gives their two-letter codes (in a order matching that of the state-name sequence). Making use of this module might save you some typing.

Project 5B

Write a program that prompts for a clothing catalog item to be entered from the keyboard, then displays it on the screen in standard form.

standard form
item-name, color, size, price
Example:
shirt, red, L, $12.95

Possible colors are red, orange, yellow, green, blue, purple, black, white, brown, and puce. Possible sizes are S, M, L, XL, and XXL, and these may be spelled out as small, medium, large, extra-large, and double-x, or abbreviated as sm, med, and lg. There are no abbreviations for colors.

This form, along with its variations described below, are the only forms of data your program is required to deal with.

Any or all of the commas may be missing, and the dollar-sign in front of the price may be missing. Any part of the entry may be all capital letters, all lower case, or any combination. For example, the color red can be entered in eight different ways: red, Red, RED, rED, ReD, rEd, REd, or reD. Orange is even worse, of course.

Regardless of the form in which the catalog item is entered, it must be displayed in standard form. Capitalization within the item-name must be as entered. However, color in standard form is all lower case, and size is all caps; price in standard form includes a dollar-sign.

Include a function in your program that converts from a string containing a catalog item in any of the allowed entry forms to a tuple of type (String, String, String, Float) in which the first component is the item name, the second the color, the third the size, and the fourth the price. This will be known as an item-tuple.

Include another function that converts from an item-tuple to a string in standard form. Use both functions profitably in your program.

Package the conversion functions in a module called ItemEntry. Import these functions into your main module, where the input/output commands reside.

Project 5C

Write a program that prompts for a date to be entered from the keyboard, then displays that date on the screen in standard form.

standard
month day, year
Example: December 19, 1996
military
day month year
Example: 19 December 1996
numeric
month/day/two-digit-year
Example: 12/19/96
modern
year month day
Example: 1996 December 19

These forms, along with their variations described below, are the only forms of data your program is required to deal with.

The month portion of a date entered in standard, military, or modern form may be all capital letters, all lower case, or any combination, and it may be abbreviated by the first three letters of the name of the month. For example, April, APRIL, ApRiL, and APr are, among others, possible entries indicating the month of April.

Regardless of the form in which the date is entered, it must be displayed in standard form without abbreviations and with the first letter of the month capitalized and the remaining letters lower case.

Include a function in your program that converts from a string containing a date in any of the allowed entry forms to a tuple of type (Int, Int, Int) in which the first component is the year, the second the month (1 for January, 2 for February, etc.), and the third the day. This will be known as a date-tuple.

Include another function that converts from a date-tuple to a string containing the date in standard form. Use both functions profitably in your program.

Package the conversion functions in a module called DateEntry. Import these functions into your main module, where the input/output commands reside.

Ground Rules