CS 1101 - Aterm 11
Homework 3 - Unions and Simple List Processing
Due: Tuesday, September 13 at 5pm
Read the expectations on homework.
Assignment Goals
- To make sure you can define unions (itemizations)
- To make sure you can write programs over unions
The Assignment
Willslist provides online classified ads in a number of categories. Users
who post ads
are charged for service-offered and help-wanted ads, but for-sale ads are free. When a
posting is made to Willslist, certain information must be provided:
- for-sale Information required for items posted for sale include
the category of the item (furniture, books, cars, cds, etc.), the city where
the posting should be published, the poster's contact information (email address or telephone number), a description of the item, and the cost of the item.
- service-offered The information required for service ads are the
type of service (for example, pet services or tutoring), the city,
a description, and the cost per hour of the service. In order to post a service ad, the poster must have a Willslist account,
which consists of an email address, password, and credit card number; this account information must
be provided when posting a service ad.
- help-wanted The information required for a help-wanted ad includes
the type of job (education, accounting, etc.), the city, a description of the
job, the number of days the ad is to run, and the poster's Willslist account
information.
Writing Programs for Unions
- Develop a data definition for each type of
ad described above, and for classified ads in general.
Provide at least one example for each data definition you make.
- Provide the template for each data definition you made in Problem 1.
-
Write a function
posted-in-Worcester?
that consumes a classified
ad and
returns true if the ad is posted for the city of Worcester. The function
returns false otherwise.
- Write a function
cost-of-ad
that consumes a classified ad
and returns a number. If the ad is for an item for-sale, the function
returns 0. Service ads automatically run for 30 days, for a flat rate of $25.
Help-wanted ads cost $10 a day.
- Write a function
update-account-info
that consumes an
ad and an account. If the ad is a for-sale type of ad, the function returns
the ad unchanged. Otherwise, the function returns an ad the same as the
original, except that the account information has been changed to the given
account.
Writing Programs for Simple Lists
- Write the data definition and the template for a list-of-string. Provide examples of 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?
)
- Write a function
got-word?
that consumes a list-of-string and
a string and produces a boolean indicating whether or not the given string
occurs in the list.
- Write a function
found-duplicate?
that consumes a list-of-string and a string and produces a boolean indicating whether or not the given
string occurs at least twice in the list. (Hints: use your function from the
previous problem as a helper)
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.