CS 1101 (A05) Homework 3: Mixed Data and Basic Lists

Due: September 13 (Tuesday) at 11:59pm via turnin (assignment name hwk3).

Assignment Goals

Remember to follow the Expectations on Homework when preparing your solutions, including the academic honesty policy.

This assignment uses Beginner Language level (what we have been using all term).


Writing Programs for Mixed Data (required)

A bank offers two kinds of accounts: checking and savings. Both kinds of accounts contain a customer's name and their current balance. Checking accounts also include a monthly interest rate (like 1.5%). Savings accounts also include the number of withdrawals the customer has made this month, the maximum number of withdrawals the customer is allowed to make each month without paying a fee, and the fee for each withdrawal over the limit.

  1. Develop data definitions for accounts. Provide examples for every define-struct that you write (you may write more than one).

  2. Write the template over accounts.

  3. Write a function enough-funds? that consumes an account and the amount that the customer wants to withdraw from the account and produces a boolean indicating whether the account has enough funds to cover the withdrawal plus fees (if applicable). A fee would apply if this withdrawal is over the number allowed on the account in a month.

  4. Write a function start-month that consumes an account and produces an account. If the original account is a checking account, the balance in the produced account is increased by the interest rate. If the original account is a savings account, then the number of withdrawals made for the month is set to zero. All other pieces of each account remain the same.

Writing Programs Over Lists (required)

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 and template for list-of-words.

  2. Write a function score-by-length that consumes a list of words and produces the total number of characters appearing in all of the words in the list. Count duplicates.

  3. Write a function long-words that consumes a list of words and produces a list of all the words that have more than 5 characters.

Download the teachpack string-extras.scm. It provides a function 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 in some of the remaining problems.

Choose ONE of the following two sets of questions

Option 1: Basic Functions on Lists of Words

  1. Write a function double-t? that consumes a list of words and produces a boolean indicating whether any word in the list has at least two uses of letter "t".

  2. Write a function count-with-letters that consumes two letters (strings of length 1 like "e" or "s") and a list of words and produces the total number of words in the list that contain both letters. Assume the two letters are different.

  3. Write a function score-by-letters that consumes a list of words and produces the score for those list of words according to the following criteria: each word gets one point per letter, with an additional 5 points for each "j" or "f", and an extra 10 points for each "q" or "z".

Option 2: Harder Functions on Lists of Words

  1. Write a function times-used-letters that consumes a list of words and a list of letters (strings of length 1, like "e" or "t") and produces the total number of uses of the letters (from the letters list) in the words (from the word list). For example, (times-used-letters (cons "hello" (cons "world" empty)) (cons "l" (cons "o" empty))) would produce 5. Assume the letters in the list of letters are all distinct.

  2. Develop a data definition and template for non-empty lists of words.

  3. Write a function longest-word that consumes a non-empty list of words and returns one of the longest words in the list (if multiple words have the same length, just return one of the words of that length).


What to Turn In

Turn in a single file hwk3.ss or hwk3.scm containing all code and documentation for this assignment. Make sure that both students' names are in a comment at the top of the file.


Help! How Do I Get Started?

Data definitions and templates first! Think about what data you need for this problem, which of it belongs together, and how the various forms of data should be related. Develop templates. Then turn to the programs. Use the design recipe worksheet if you want guidance through the steps.

Post other questions to the discussion board or come to office hours.


Back to the Assignments page