BU CAS CS 113
Introduction to Computer Science II with Intensive C
Fall 1997


Assignment 7: Hash Tables


Last Modified: Mon Nov 24 07:39:38 1997

Deadline

November 25, 1997

Note: Because of the holidays, anything turned in by 11:59 pm on Monday, December 1, will count as only one day late.

What to Submit

Be sure the files you submit have exactly the following names: hw7-delete.c hw7-inv.c .

These programs are to be electronically submitted by using the submit program on csa. The code you submit should conform with the program assignment guidelines.

Deleting from a Hash Table

The symbol table in Programming Abstractions in C does not include a function for removing things from the table. You must implement hw7-symtab.h, which extends the symtab.h interface of Programming Abstractions in C to include one additional function
/* Function: DeleteKeyFromSymbolTable
 * Usage:    value = DeleteKeyFromSymbolTable(table, key);
 * ------------------------------------------------------- 
 * This removes key (and it associated value) from table,  returning
 * the value associated with key or UNDEFINED if key is not in table.
 */

void *DeleteKeyFromSymbolTable(symtabADT table, string key);

To save space on the system and in the grader's files, please submit just the implementation of this one function in hw7-delete.c. Here are some files you might want to look at:

Using a Symbol Table

Write a program to do simple inventory operations. Your program should store in a table item names, prices and quantities. Your program should handle the following commands:
    A - Add item
    D - Delete item
    L - Lookup item
    I - print Inventory list
    < - print Inventory list for items with quantity less than specified amount
    X - print most expensive item (with price and quantity)
    Q - quit

Some of these take additional input (in order listed): A (item, price, quantity), D (item), L (item), < (quantity). Each operation which prints one or more items should give the item followed by price, followed by quantity in nice columns. (You may print only the first 15 characters of an item with a long name.) The order in which items are printed (when more than one is printed) is irrelevant and will probably be in some "random" order which depends on the hash function used. If the user tries to lookup something not in the table, an appropriate message should be displayed.

Input/Output. Each input value should be requested on a separate line. This will make your lives easiest, since you will not need to parse the input. You may read the commands as strings and then just look at the first character. (I will not require that you program handle inputs of more than one character, but this is an easy method to do so.) Thus a sample run might look like:

command (A,D,L,I,X,<,Q): A
     item: hammer
    price: 7.50
 quantity: 10

command (A,D,L,I,X,<,Q): D
     item: nails
  
     nails not present in table.  Nothing deleted.

command (A,D,L,I,X,<,Q): I

  Current Inventory
  ======= =========
  item             price     quantity
  ----             -----     --------
  hammer           7.50      10


command (A,D,L,I,X,<,Q): Q
You may adjust the format of the output as ong as it is easy to read and presents the appropriate information. If you do not implement all of the commands, be sure you still ask for all of the requested inputs and print a message to the effect that the command has not been implemented.

Makefile

To check that your assignment compiles correctly, use the Makefile for this assignment:
  1. Copy this Makefile into the directory where your programs are.
  2. Name it Makefile.
  3. type: make -k. (The -k means "keep going", which instructs make to build as much as it can, rather than quit after the first error.)

Academic Honesty and Collaboration

It is reasonable to discuss with others possible general approaches to problems. It is unreasonable to work together on a detailed solution, to copy a solution, or to give away a solution. If your common discussion can be detected by looking at the solutions, then there is too much collaboration. Such instances of academic dishonesty may result in a course grade of F or expulsion from Boston University.

Do not allow your work to be used by others:

Warning: If someone cheats by using your work, you will also be penalized.