Lists of structures — CD store
posted by: Ms. Martin
30 September 2010
No Comment
Part I: more 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.
- Write the data definition and template for list-of-words.
- Write a function
score-by-lengththat consumes a list of words and produces the total number of characters appearing in all of the words in the list. Count duplicates. - Write a function
long-wordsthat consumes a list of words and produces a list of all the words that have more than 5 characters.
Part II: lists of structures — CD store
We want to develop a database for a CD store. For each CD, the database must store its title, how many are in stock, and its category of music (such as “trip-hop”, “afro-cuban klezmer” or “post rock”). You must get 1-6. 7 is a challenge! Impress me.
- Develop a data definition for CDs and provide at least 3 examples.
- Develop the data definition for a list-of-CDs and provide at least 3 examples of a list-of-CDs (using examples for CDs developed above).
- Write a template for functions over CDs (a comment using … to show missing code).
- Write a template for functions over list-of-CDs. Make sure to use your previous template.
- Write a function total-stock that consumes a list-of-CDs and produces the total number of CDs available.
- Write a function category-stock that consumes a string (category) and a list-of-CDs and produces a list of all the CDs that are in the given category and in stock.
- [*] Write a function unique-categories that consumes a list-of-CDs and produces a list of categories in the list-of-CDs. The output list should contain no duplicates.






