CS 1101 - Aterm 10

Homework 4 - Basic Lists

Due: Tuesday, September 14 at 5pm

Read the expectations on homework.

Assignment Goals


The Assignment

Writing Programs over Lists

  1. Write the data definition for list-of-word (list-of-string). Make at least three examples of data.

  2. Write the template for a function over a list-of-word.

  3. Write a function got-word? that consumes a list of words and a word and produces true if the given word occurs at least once in the list.

  4. Write a function found-duplicate? that consumes a list of words and a word and produces a boolean indicating whether or not the given word occurs at least twice in the list. (Hint: use your answer to Problem 3)
In the remaining exercises, you will develop a function that consumes a list of words and produces a struct. The struct keeps track of the number of occurrences of certain words: "fizzle", "bump", and "splat".
  1. Provide a data definition for a structure that keeps track of the number of occurrences of the words "fizzle", "bump", and "splat". Name your datatype fbs. Provide at least one example of an fbs.

  2. Write the template for functions over fbs's.

  3. Write a function called count-occurrences that consumes a list of words and a word and counts the number of occurrences of the given word in the list.

  4. Use your answer to problem 7 as a helper to write a function with the following contract and purpose:
    ;; list-to-fbs:  list-of-word -> fbs
    ;; consumes a list of words and produces an fbs that records the number of
    ;; times the words  "fizzle", "bump", and "splat" appear in the list.
    
    Here are some test cases you can use to test your function:
    (check-expect (list-to-fbs empty) (make-fbs 0 0 0))
    (check-expect (list-to-fbs (cons "bump" (cons "bump" (cons "fizzle" empty))))
                  (make-fbs 1 2 0))
    (check-expect (list-to-fbs (cons "splat" (cons "drip" empty)))
                  (make-fbs 0 0 1))
    
    (Hint: this function does not strictly follow the template (it doesn't use the operators first and rest on the list-of-words). Most of the functions we'll write this term follow the templates, but occasionally we'll come across one that doesn't.)

What to Turn In

Here is the gradesheet for Homework 4.

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. Put both partners' names and wpi login names in a comment at the top of the file.