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.

  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.

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.

  1. Develop a data definition for CDs and provide at least 3 examples.
  2. 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).
  3. Write a template for functions over CDs (a comment using … to show missing code).
  4. Write a template for functions over list-of-CDs.  Make sure to use your previous template.
  5. Write a function total-stock that consumes a list-of-CDs and produces the total number of CDs available.
  6. 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.
  7. [*] 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.
1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 2.50 out of 5)
Loading ... Loading ...

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>