CS 1101 - Cterm 10

Homework 4 - Basic Lists

Due: Tuesday, Feb 2 at 5pm

Read the expectations on homework.

Assignment Goals


The Assignment

Writing Programs over Lists

Imagine that you are writing programs that are part of a word game (like Scrabble or Boggle) in which players get points for the words they can come up with during the game.
  1. Write the data definition for list-of-words (list-of-strings). Make at least three examples of data.

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

  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.

Download the teachpack string-extras.scm . It provides a function called char-count that consumes a string of length 1 and a string of any length and produces a number indicating how many times the first string appears in the second string. You'll need it for problems 4-6.

  1. Write a function num-words-with-letter that consumes a list of words and a letter (i.e. a string of length 1), and produces a number. The function produces the number of words in the list that contain at least one occurrence of the given letter.

  2. Write a function words-with-two that consumes a list of words and a letter and produces a list of all the words that contain exactly two occurrences of the given letter.

  3. Write a function score-words that consumes a list of words and produces the score for that list of words according to the following criteria: words are scored by giving one point each per letter, except "z", "q", or "x", which are worth 5 points each.

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 9 as a helper to write a function with the following contract and purpose:
    ;; list-to-fbs:  list-of-words -> 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))
    

What to Turn In

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.