Assignment 2: Structures (due Sept 15)


Before you tackle the homework, remind yourself of our General Advice, Advice on Homeworks, and Grading Guidelines. Above all, keep your work neat and honest.


This week's assignment is the first in a three-part series on using Scheme to generate web pages. Be sure to save a copy of all programs that you turn in this week.

Like the guessing game problem from last week, this assignment uses a library. The library provides most of the define-structs and the programs needed to generate web pages. You will write a few remaining programs. When you test your programs (we tell you how below), DrScheme combines your programs with those in the library to form the complete program. You do not need to understand the code that is in the library. Furthermore, you do not need to know anything about creating web pages in order to do this assignment. Here's a sample of the page that you'll be generating this week.

This assignment uses the library hwk2-lib.ss. Using your web browser, download this library file to your working directory. When you use set-library-to, use the path of your working directory to load the library. Ask the labbies for help with this if need be!


Problem Background

Scenario: A music store, Sammy's Music, wants to generate a web site for their inventory information. Sammy's already has a database containing all of their inventory information. They stock music in three categories: classical, rock, and blues. They sell music in two formats: tape and cd. Sammy's database uses three structures: one for albums, one for music formats, and one for stock items. The data definitions for all of this information are as follows:

;; A music-category is one of
;;   - 'classical
;;   - 'rock
;;   - 'blues

;; A music-format is one of
;;   - 'cd
;;   - 'tape

;; An album is a structure
;;  (make-album artist title category)
;; where artist and title are strings and
;;       category is a music-category

(define-struct album (artist title category))

;; A format is a structure
;;  (make-format type copies price)
;; where type is a music-format and
;;       copies and price are numbers

(define-struct format (type copies price))

;; A stock is a structure
;;  (make-stock album cd tape)
;; where album is an album structure and
;;       cd and tape are format structures or false (if Sammy's
;;         does not stock the album in that format

(define-struct stock (album cd tape))

NOTE: hwk2-lib.ss provides the three define-structs listed above. Do not retype them in your file or your programs will not work properly.

Sammy's advertising department has hired you to manage their database and create web pages for their on-line store. As Sammy's does a brisk business, their inventory changes regularly. Making these updates and changing the web pages manually through all of these changes would be boring. Therefore, we want to write programs to handle these tasks.


This Week's Assignments

  1. (3 pts) The web page separates Sammy's inventory into the different categories of music that they stock. Write a program in-category? which consumes a stock item and a music-category. It returns true if the album in that stock item is in the given category and false otherwise.

    Set the library to hwk2-lib.ss and test your program using

         (gen-page/1 in-category? base-inventory)
    

    Hwk2-lib.ss defines base-inventory for you. The sample page has been generated from base-inventory. Running gen-page/1 will generate an HTML file called 210Music.html in your directory. Use your favorite browser to view 210Music.html.

  2. (6 pts) Sammy's currently updates their inventory manually. You want to help them automate their inventory management. An inventory update consists of five pieces of information: the artist and title of the album to update, the format to update (cd or tape), and the changes in the number of copies and the price of the album in the given format (The change should be the difference between the old number of copies and the new, not the new number of copies. Same for the price).

    1. Define a structure and examples for updates. Be sure to include a full data definition.

    2. Write a template for a program which consumes an update and a stock item.

    3. Write a program apply-update? which consumes an update and a stock item. It returns true if the artist and title in the update are the same as those in the stock item; otherwise, it returns false. (For this program, you will need to compare strings using the operator string=?).

    4. Write a program update-stock which consumes an update and a stock item. It returns a new stock item that adjusts the copies and price of the original stock item according to the update.

      The library provides a function update-db, which consumes your programs apply-update? and update-stock, as well as an update struct and an inventory. update-db returns a new inventory. Test your programs using

           (gen-page/2 inv)
      
      where inv is an inventory. So, for example, you could use
           (gen-page/2 (update-db apply-update? update-stock (make-update ...) base-inventory))
      
      where make-update is created using the struct you defined above.

      Running gen-page/2 will replace 210Music.html with the page for the new inventory. If you press the reload button on your browser, you should see the changes resulting from the update. In your test cases for this problem, generate a page containing at least two updates to the original inventory.


Summary: What does the library provide?

Summary: What do you need to write?





Kathi Fisler This page was generated on Wed Sept 8 16:01:35 CDT 1999.