CS 1101 - Aterm 11

Homework 3 - Unions and Simple List Processing

Due: Tuesday, September 13 at 5pm

Read the expectations on homework.

Assignment Goals


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:

Writing Programs for Unions

  1. 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.

  2. Provide the template for each data definition you made in Problem 1.

  3. 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.

  4. 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.

  5. 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

  1. Write the data definition and the template for a list-of-string. Provide examples of list-of-string.

  2. Write a function character-count that consumes a list-of-string and counts the total number of characters in all strings in the list.

  3. 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?)

  4. 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.

  5. 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.