Cluster 5 * Summer 2004
Computer Science Through Games and Scheme Programming
David G. Kay, Dan Frost, Kevin Papke


Scheme Lab Activities: Third Set

  1. From the Scheme course home page, you can find a program that maintains a "database" of restaurants. It's called restaurants.ss.
    Make your own copy of this file and open it in DrScheme. Evaluate it by clicking the green arrow. Then, in the interactions (lower) window, type (Restaurants) to run the program, typing commands to add, remove, print, and search for restaurants. Spend some time getting familiar with what the program does.
    [For simplicity, the Restaurants program asks users to enter nonnumeric information as double-quoted strings. Of course it's possible to write Scheme programs that don't require the user to type double quotes; that's just a detail that we'll put off for now.]

  2. You'll find many unfamiliar aspects of Scheme in this code. That's fine; we'll explain them all before the month is over. But it's a good skill to try to navigate your way around a program, even when parts of it are temporarily obscure, gathering clues from the parts you do know. Try each of these activities:

    1. Modify the code so that the command for adding a new restaurant is 'n' instead of 'a'. (This should require a change in two places.)

    2. When you print the collection of restaurants, it would be nice to have a blank line separating the information on each restaurant. Modify the program to achieve this. (You only need to add one procedure call--(newline)--in one place.)

    3. Modify the program code so that it gives the user an additional menu choice:
      e: Remove (erase) all the restaurants from the collection
      When the user types 'e', the program should remove all the restaurants from the collection (so that, for example, if the next command were 'p', nothing would be printed).
      [This will require modifications or additions in a few places. You can do the main part of the work very easily indeed, with a single procedure call. The key is to think functionally, not of changing values but of describing or creating the new value. How would you describe a collection with all the restaurants removed?]

    4. Modify the program so that it adds another menu item:
      a: Adjust prices for the dishes served
      When the user types 'a', the program should ask the user for an amount (positive or negative) representing a percentage change in price (so that 100 would double a price and -50 would cut it in half). Then it should apply that price change to the prices for all the restaurants in the collection.
      [Here are some hints on how to approach this. If you want to be cool, you can postpone looking at them. You might approach this first by writing a change-price procedure that takes a restaurant and a percentage change number, as above, and returns a restaurant that has all the same information, except that the price is changed appropriately. Next you might write a call to collection-change that uses change-price and changes the prices in all the restaurants in the collection. Finally, you can incorporate these calls into the main program, adding the appropriate command handling and so on.]



COSMOS Cluster 5 Home * COSMOS UCI Home

David G. Kay, 406B Computer Science
University of California, Irvine
Irvine, CA 92697-3425 -- (949) 824-5072 -- Fax (949) 824-4056 -- Email kay@uci.edu

Tuesday, July 13, 2004 -- 11:27 AM