Assigned | Feb 9th, 2003 | |
Due | Sunday Feb 23, 2003 by 11:59PM | |
Updates | Feb 11, 2003
In keeping with our definition of List, you may assume that there will be no duplicate BUY transactions It seem's my keyboard was stuck when typing this project description.... the correct name for the data structure is Deque, not Dequeue. |
Using one ADT to implement another is an important programming concept known as "layering". The user of the deque doesn't know there's a LinkedList underneath. The deque's methods are implemented using the LinkedList methods.
Deque is derived from "double ended queue". It's similar to a queue, but allows equeuing and dequeing from both ends. These operations are referred to as "InsertAtFront", "InsertAtBack", "RemoveFromFront" and "RemoveFromBack". In the C++ STL, stacks and queues are implemented using a deque.
Pictorially, a deque looks like this.
When a share of a common stock of some company is sold, the profit (or, sometimes, loss) is the difference between the share's selling price and the share's purchace price. This calculation is easy to understand for a single purchase and single sale.
When we buy shares of stock over a long period of time and then decide to sell some (but not all) of them, we must identify the shares actually being sold. The accepted method for identification is to assume that the shares being sold are the ones that were bought first (the ones we've owned the longest).
For example, suppose we buy 100 shares at $10 per share on day 1; 200 shares at $25 per share on day 2; and 200 shares at $30 per share on day 3.
Sometime later, we sell 100 shares for $35 each. Applying the "sell the oldest ones first" principle means that the 100 shares we sold were the 100 which were bought on day 1 and our profit on the sale is 100 * (35 - 10) = $2500.
Sometime later we sell 300 shares at $27 per share. These 300 shares consist of the 200 shares bought on day 2 and 100 of the 200 shares bought on day 3. So our profit is 200 * (27 - 25) + 100 * (27 - 30) = $400 - $300 = $100. The 100 shares bought on day 3 will be the first ones sold the next time we sell shares.
Because shares are sold in the same order they are purchased, this application can be supported by a FIFO ADT such as a deque.
Your modifications must be limited to the following. No other changes
to the Linked List code are permitted.
You must design and implement the transaction class as you see fit
based on the project requirements. Keep your design simple -- very
few methods or data elements are required. It is not necessary to
implement the default constructor, copy constructor, assigment operator
and destructor if the compiler's default implementation is sufficient.
Linked List Modifications
Your Deque will use a modified version of the author's Linked List
code to actually store the data in the Deque. The author's code
(LinkedList.H and LinkedList.C)
should be copied from Mr. Frey's public directory
/afs/umbc.edu/users/d/e/dennis/pub/CMSC341.
This code has been modified for g++ v3.2.1 and has been successfully
compiled and tested on linux.
Note that the Deque may not be a friend of any class or function and no
class or function may be a friend of the Deque.
A transaction class
Your program will read "BUY" and "SELL" transactions from a command
file. The BUY transactions will be stored in the deque. SELL
transactions will be processed as they occur.
The Command Line
Project 2 will be invoked with a command line that consists of a single
argument -- the name of the transaction file to read.
As
usual, you should check the validity of all command line arguments.
If you don't submit a project correctly, you will not get credit for it. Why throw away all that hard work you did to write the project? Check your submittals. Make sure they work. Do this before the due date.
Documentation for the submit program is on the web at http://www.gl.umbc.edu/submit/. One of the tools provided by the submit program is submitls. It lists the names of the files you have submitted.
Additionally, there are two programs which are not part of the
UCS submit program. They are in the directory
/afs/umbc.edu/users/d/e/dennis/pub/CMSC341/ and are
named submitmake and submitrun. You can use
these programs to make or run your submitted projects.
To access these programs, do one of the following
The syntax is similar to that for submit:
submitmake <class> <project>
Example: submitmake cs341 Proj2
This makes the project, and shows you the report from the make utility. It cleans up the directory after making the project (removes .o files), but leaves the executable in place.
submitrun <class> <project> [command-line args]
Example: submitrun cs341 Proj2 test.dat
This runs the project, assuming there is an executable (i.e. submitmake was run successfully) and that test.dat is in your local (not submittal) directory.
Project grading is described in the Project Policy handout.
Your answers to 341-Spring03-proj2_questions.txt are worth 10% of your project grade.
Cheating in any form will not be tolerated. Please re-read the Project Policy handout for further details on honesty in doing projects for this course.
Remember, the due date is firm. Submittals made after 11:59pm of the
due date will not be accepted. Do not submit any files after that time.