Winter 2005 UCLA CS 31 (Shinnerl)

Programming Project 7: Electronic Market

DUE: 10:00pm Monday, 3/14/05

Accepted without penalty until 12:01am Monday 3/21.

FINAL Specification Last Update: 7am 3/5/05

I. Overview

Implement a text-based electronic marketplace for buyers and sellers. Each user is given an account storing the following data.

User Attributes
user name an identifier used to associate a given user with a specific account
balance the amount of money in the users account, in US dollars
stock a list of the items currently offered by the user for sale to other users
sales a record of all sales transactions to date in which items previously held in the user's stock were bought by other users
purchases a record of all sales transactions to date in which the user bought items from other users

A user enters the market simply by running the program and logging in with his/her user name. After that, the following main menu is printed to the output console.

                  acct   ---  View my account or update my stock.
                  shop   ---  Shop for items in the market inventory.
                  exit   ---  Leave the market.
                     ?   ---  Display this menu.
This menu is displayed in response to any command other than acct, shop, or exit. Otherwise, after all subsequent acct and shop commands have been completed by the user, the following abbreviated main prompt is displayed instead.
                  acct shop exit ?> 
The program terminates when the user types in exit at this prompt. Each of the acct and shop commands activates a separate menu-driven subprogram, as described below.

Each item in stock has the following records associated with it.

Item Attributes
item name a one-word identifier for the item
item description an English description of the item
quantity the number of such items the user currently offers for sale
price the price of the item in US Dollars.

A user can store as many items of the same item name and description as s/he wishes; distinguishable items offered for sale by the same user must have different names. However, different users can offer different items under the same item name. E.g., although Alice can offer only one type of item called "book," and Bob can offer only one type of item called "book," Bob's books most likely will have a different description from Alice's.

By inventory, we mean the collection of all items currently for sale by all users. That is, the inventory is the union of all users' stocks. The program automatically maintains and updates all stocks and saves this information on disk before it terminates, so that its inventory usually changes from one run to the next.

There should be no limit imposed by your program on the number of users or the number of items a user can offer for sale. (These quantities should be limited only by the amount of memory in the machine on which the program is run.) Hence, your program must use dynamically sized lists of users and their items.

II. Details

  1. Logging In. A user entering the market is required to provide a short user name used by the program for identification. If that user name already exists, then the program prints the user's full name to the screen and asks the user to confirm that s/he is in fact that person (a password is not required). Otherwise, the program informs the user that the given user name is new to the market and asks him or her to confirm that s/he would like to create an account associated with that user name. If so, then the program creates that user's account and appends it to a list of accounts. If not, then the program terminates.

  2. Shopping. When a user enters the command shop at the main prompt, the program displays the following shop menu.
      search   ---  search for items in inventory
      buy      ---  purchase an item
      return   ---  return to the main menu
           ?   ---  display this menu
    
    This menu is displayed in response to any command other than search, buy, or return. Otherwise, after all subsequent searches and transactions by the user, the abbreviated shop prompt
        search buy return ?> 
    
    is displayed instead.

  3. Accounts. When a user enters the command acct at the prompt, the program displays the following acct menu.
      profile  ---  change my user name or delete my account
      history  ---  view my lists of sales and purchases
      add      ---  add a new type of item to my stock
      update   ---  update the quantity or description of an existing item
                       in my stock
      return   ---  return to the main menu
           ?   ---  display this menu
    
    This menu is displayed in response to any command other than profile, history, add, update, or return. Otherwise, after all subsequent selections by the user, the abbreviated account prompt
    profile history add update return ?> 
    
    is displayed instead.

    These commands allow the user to modify his/her account profile and stock however s/he wishes in an obvious way. If the user changes the quantity of an item to 0, the program automatically removes that item from the user's stock.

  4. Market State File. The program maintains up-to-date lists of all users and their stocks in a single large file named marketState.txt. This file represents the market's state only when the program is not being run. During execution, the program's updated account information is maintained in primary memory ("RAM") only, and not on disk in the state file. The list of users and/or inventory typically change from run to run, and all changes are automatically recorded in the state file every time the program terminates. The easiest way to keep the state file up to date is probably to just to overwrite the entire file with all users' names and stocks at the end of each run. With this strategy, the program's use of files is simplified, as follows. When the program is invoked, it loads all user names and their corresponding account information into RAM. As a user makes transactions, the affected stocks of other users are updated in main memory but not on disk (the state file is not updated as transactions are made). When the user exits, all stocks must be rewritten to disk in their correct, updated states.

    For grading purposes, the format of the market-state file is prescribed. Please follow the prescribed format carefully, in accordance with the sample posted separately. The format of the market-state file should be easy to figure out just by looking at the example. The format uses the following rules.

    1. A line beginning with a # symbol is interpreted by your program's parser as a comment. Everything on that line should be ignored.
    2. All fields of all records are tagged with XML-style delimiters. The tags for a field belonging to a record are nested within the tags for the record itself.
    3. White space (tabs, spaces, and newlines) between tags and words is ignored by the parser, but white space between words in the same field is not.
    4. White space between a closing tag and the next opening tag is ignored.
    5. Indentation is not part of the format; however, indentation is used to facilitate human readability --- see the example.
    6. For convenience, the format of an item in a user's sales history or purchase history is the same as the format of an item in the user's stock. In these contexts, the quantity field refers to the number of items sold or bought in the given transaction.
    Hence, there is no rule against putting as many blank lines in the file as desired.

III. Simplifications

IV. Submission

Submit a single zip file containing source file p7.cpp and report file report.s1.
Project 7 Home Page