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
-
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.
- 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.
-
Searching.
If the user enters search at the shop prompt,
the program asks the user to enter either a search phrase or
the key word show all.
If the user requests show all, then the entire market inventory
is displayed to the screen. Otherwise,
the program tries to find an exact match of the search phrase
to some item name. Failing that,
it tries to find an item description of which the search phrase
is a substring. It displays complete information of
all matching items to the screen, including item descriptions
along with the names of their sellers.
-
Buying.
If the user enters buy at the shop prompt, the
program asks the user to enter the desired item's name.
If the item name requested is not in inventory,
an error message is printed
and control returns to the shop menu. If the item is offered by
more than one seller, the buyer is prompted to identify which
seller's item s/he wants. Once a selection is made, the program
updates the buyer's and seller's balances and transaction histories.
The seller's stock is updated, but the buyer's stock is not.
(The program assumes that buyers buy items for their personal use.
If a buyer wishes to sell an item s/he previously purchased, s/he
must explicitly add it to his/her stock.)
-
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.
-
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.
- A line beginning with a # symbol is interpreted
by your program's parser as a comment. Everything on that
line should be ignored.
- 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.
- 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.
- White space between a closing tag and the next opening tag
is ignored.
-
Indentation is not part of the format; however, indentation is
used to facilitate human readability --- see the example.
-
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
- The simulated market is not a secure system. Passwords are not used
and records are not encrypted.
Users are identified simply by their user names, without any verification.
The program assumes that users are honest and that all users
trust each other.
-
Lists are stored in dynamically sized arrays or
in std::vector<...>s and need not be sorted.
Finding a record in
a list may take time proportional to the length of the list.
To remove an item or user from a list, just swap
the user or item with the current last element of the list
before removing it, in order to keep the array data contiguous.
-
The program does not support concurrent users.
There is no way to switch users without terminating the program.
-
The program assumes buyers have an external way of obtaining their
purchased items. Shipping is ignored.
- The single-file recordkeeping system simplifies your coding
but is not efficient. Note that even with one million users,
a single transaction would require copying all market records twice,
from disk to RAM and back, even though only two users' records
are modified. A more efficient multiple-file recordkeeping system will
be considered in Written Assignment 2.
IV. Submission
Submit a single zip file containing source file p7.cpp
and report file report.s1.
Project 7 Home Page