C++ fix

profilef.a.qx8t
programspecification2.docx

CSC 2110: Data Structures and Algorithms

Programming Assignment 2, Inventory Management

Due: October 13, 2014 200 Points

General Policy:

There is to be no sharing of any code not given by me. This includes any test drivers you create. As outlined in the syllabus, you will not receive help on the extra credit (if any) outlined in the program specification. Furthermore, you will not receive any help on the assignment (extra credit or otherwise) on or after the day the program is due. Don’t procrastinate! It WILL end badly.

Array-Based Deque

Create an array-based deque implementation (DequeArray). You may use QueueArray from the examples page to get started. Your implementation should not use shifting, but instead use a circular array implementation. This means you must move the front and back when dequeueing and queueing instead of shifting the array contents forward when dequeuing. To do this, you will need to store the an index for both the front and back of the queue. Allow array resizing if the array runs out of room. Write DequeDriver to thoroughly test your Deque implementation. The (public) operations required bt the Deque ADT are as follows:

· bool isEmpty()

· int size()

· void dequeueAll()

· T* peek()

· void enqueue(T* item)

· T* dequeue()

· T* peekDeque()

· void enqueueReverse(T* item)

· T* dequeueReverse()

StackDeque and QueueDeque

Implement a standard stack and queue using your new DequeArray.
Inventory Management

Create a simple inventory management system for a business which buys and sell Widgets. Your system should allow the user to choose either LIFO or FIFO inventory tracking. The profit computed using the two methods will be very different. LIFO uses the cost of the Widgets bought last to compute profit. FIFO uses the cost of the Widgets bought first to compute the profit. Thus, since the cost of an item increases over time in an inflationary economy, LIFO reports lower profit than FIFO. LIFO is often used to report income for tax purposes, while FIFO is used to report profit to shareholders.

Write a Widget class (.h and .cpp) to store the cost that you paid for a Widget. The cost is the only instance variable.

Write an InventoryManager class (.h and .cpp) to maintain your inventory and report profit. The constructor accepts an integer (or a boolean) to determine whether LIFO or FIFO is being used. Once selected, this inventory management choice cannot be changed.

Based on the inventory management choice, instantiate either a StackDeque or a QueueDeque. When you buy Widgets, push or enqueue the number of Widgets bought, storing the cost that you paid for the Widgets. For example, if you bought 7 Widgets for $5, you will create 7 Widgets, each with cost $5, and you will call push 7 times, once for each Widget. When you sell Widgets, pop or dequeue the number of widgets sold, computing your profit based on the selling price and the cost extracted from each of the Widgets sold. If there are not enough Widgets for the requested number to sell, sell as many widgets as there are (ignore overselling).

Write the following methods in your InventoryManager class:

· InventoryManager(int inventory_choice) //LIFO or FIFO

· ~InventoryManager()

· void buyWidgets(double cost, int num_to_buy)

· double getTotalProfit()

· double sellWidgets(double price, int num_to_sell)

Inventory Driver

Download the InventoryDriver (some of this is completed for you) which will allow you to buy and sell Widgets and will report the profit (loss) when you sell Widgets. When the user exits, the InventoryDriver reports the total profit for all transactions.  Note that this driver does not use any global variables. All user interaction is present in the driver. InventoryDriver does not have direct access to the Stack or Queue.

· Program02Files.zip

· InventoryDriver.cpp // You will need to complete this

Documentation

Fully document your InventoryManager class, including:

· Preconditions and Postconditions

· Class level comments

Program Output Sample

http://mboshart.dyndns.org/boshart/2110programs/prog2/prog2.jpg

*This document relies heavily on the work of Dr. Mark Boshart.