2.13 More Lists of Objects
A list of objects
is like a list of atomics
Except, it’s objects
2.13.1 Objectives
2.13.2 Exercises (due 2011/10/31 08:45:00)
1. Develop a data definition for CDs. You should at least keep track of the title, artist, price, number in stock, and its category (such as "K-Pop", "Soundtrack", "Nerdcore", etc.) Make 8 CD objects with at least three categories.
2. Develop a data definition for CD inventories—
3. Write a function, copiesInStock, that consumes a CD title, artist, and inventory and produces the number of copies of the item in stock—
4. Write a function, restock, that consumes a CD title, a number of new copies, and an inventory and produces an inventory where the named CD’s stock has increased. Assume the CD is in the inventory.
5. Write a function, titlesBy, that consumes an artist and inventory, and returns a list of titles by that artist in the inventory.
6. Write a function, uniqueCategories, that consumes an inventory and produces a list of categories. The result must not contain duplicates.
2.13.3 Optional Exercises (due 2011/11/04 08:45:00)
7. Write a function, categoryStock, that consumes an inventory and a category and produces a list of all CDs in the named category that have more than 0 copies in stock.
8. Write a function, kpopSale, that consumes an inventory and produces an inventory where all K-Pop CDs are discounted by 10%.
9. Propose and write your own function on inventories. Proposals that are too trivial or similar to required exercises will not be accepted.
2.13.4 Notes
These notes are primarily for my sake, but I don’t see any reason to hide them from you.
append |
-- start with students (3) |
-- do it myself? |
|
reverse |
|
--- |
|
noRobots : inv -> inv (no "robot") |
|
[Maybe look at String.contains()] |
|
containsThingHuh : inv name -> boolean |
|
totalItemPrice : inv name -> price [sum all the items] |
|
discount : inv name -> inv |