Assignment 3: Simple Recursion (due Sept 22)
This assignment continutes the web page generation assignment from
last week. Several of the programs in this assignment ask you to use
your programs from assignment 2. Copy the necessary programs from
assignment 2 into your files for this assignment.
Note: This assignment is not as long as it looks!
While there are many problems, each one is rather small.
Download and set DrScheme to use the library hwk3-lib.ss.
The following problems refer to two sets of data definitions: the ones for
Sammy's inventory database from assignment 2 and a
set of data definitions for HTML. The HTML data
definitions page describes the functions in the library that you should use
to generate HTML from the HTML structures. There are links from the
problems below to the parts of the data definition that you need for that
problem.
The data definitions in assignment 2 did not include one for
inventories. Here is the data definition for an inventory:
;; An inventory is either
;; - empty, or
;; - (cons S I)
;; where S is a stock and I is an inventory
A Note on Inventories: This week's library provides
the same base-inventory that you worked with last week. Now that
you've studied lists, you can create your own inventories (or add new
stock items to the base-inventory).
This Week's Assignments
- (3 pts) Write a program update-db which consumes an
update structure and an inventory and produces a new inventory that
reflects the update. Use your programs apply-update? and
update-stock and your update structure definition from
assignment 2.
Test your program by evaluating
(gen-page/2 (update-db u1 inv))
where u1 is one of your update structures and
inv is an inventory.
- (3 pts) Write a program cd-count which consumes an
inventory and returns the total number of CDs in stock (include all copies
of each CD in the total).
- (3 pts) Write a program get-stock which consumes a
music category and an inventory and returns a list of the stock items in
that category. Use your in-category? program from assignment
2.
- (3 pts) Write a program get-table-rows which consumes
an inventory and returns a list of the album data for each stock item. Use
your get-album-data program from assignment 2.
Get-stock separates the inventory items into categories;
get-table-rows generates the rows for the tables on the web
page. Test these two programs by evaluating
(gen-page/5 get-stock get-table-rows inventory)
- (3 pts) Write a program gen-category-page which
consumes a music category, an inventory, and a string containing the name
of the Sammy's Music home page and produces an html-page structure. The page must
contain at least the name of the category, a table showing Sammy's inventory in that
category, and a link to Sammy's home
page. A sample appears here.
Test your program using the library function html-to-file
(described on the HTML definitions page) as follows (filling in
... with the necessary arguments).
(html-to-file (gen-category-page ...) "210test.html")
View 210test.html with your browser to see the results.
- (3 pts) Write a program gen-category-links which
consumes a list of music categories and returns a list of html-links. The
text for each link is the name of the category. The URL for each link is
the category name followed by ".html". The library provides a function
convert-to-html-filename which takes a symbol and returns a
string containing the symbol followed by .html. Use this function to write
your program.
- (3 pts) Write a program gen-main-page which consumes an
inventory and produces an html-page
structure. The page must contain at least the message "We have [n] CDs in
stock!" where n is the result of your cd-count
program (above), the message "Please Select a Category", and a list of links to the pages for each individual
category (use gen-category-links to generate the list of links).
A sample appears here.
Test your program using html-to-file, as described above.
- (3 pts) Write a program gen-site which consumes an
inventory and produces a boolean. This program uses the library function
html-to-file to write both the main page and each category page
to a file (the files will appear in your working directory). The function
html-to-file consumes an html-page structure and a filename and
returns true. Write the homepage to the file "210SammyHome.html" and use
convert-html-to-filename to get the filenames for each category
page.
After you've generated the site, bring up 210SammyHome.html and
browse the results!
- (Extra credit, 3 pts) Your current program
assumes that Sammy's inventory contains a fixed list of categories.
Generalize your program to generate pages for every music category
appearing in Sammy's inventory. Describe how you had to change your
existing program to do this and show the new program definitions.
- (Extra credit, 2 pts) In no more than four brief
sentences, describe whether these two assignments illustrate anything about
computing and/or programming ("how to generate web pages" or "programming
is fun" don't count).
Kathi Fisler |
This page was generated on Fri Sept 10 18:01:35 CDT 1999.
|