Overview

This program serves as a shop model that mimics five basic operations. The actions below are defined in terms of the program's scope:

sell : removes an item from the store inventory

buy : adds an item to the store inventory

display : outputs the entire inventory, including the number of each item

customer : outputs all transactions for an individual customer in chronological order (includes items for each transaction)

history : outputs the transactions of all customers, sorted by customer name

Class Interactions & Main

The object performing the operations above is Store, also serving as an interface with the input files as well as three separate objects: ProductFactory, CustomerHouse, and ActionStation. Each of these classes utilizes the polymorphic behavior of object-oriented programming.

ProductFactory is responsible for creating various products within the store; a base class, Item will be open for extension, offering limitless types of products. This class will also serve as the “inventory” of the Store object, able to generate as many Product objects necessary.

CustomerHouse will also include a factory method that generates Customer objects. Within Store, CustomerHouse serves as the “customer list”.

ActionStation is slightly different from the previous two classes in that it only contains single instances of each Transaction object (Sell, Buy, Display, Customer, History). Store relies on this “commands” data member to carry out all interactions between ProductFactory and CustomerHouse. ActionStation also allows for the printing of current Store data among its responsibilities.

Hash tables are used within each of the three classes above. This data structure provides the benefit of efficient retrieval and a means for storing base and all derived classes within one array. More specifically, ProductFactory and CustomerHouse will utilize binary search trees of base and all derived class types at various slots within the hash table.

The first version of the program will include the following products:

coins | novels | action figures

main begins with Store reading an input file containing product data. The file is read until the end and parsed at each line. A second input file contains customer data while the third contains transaction data. Each of these are also read and parsed, passing the data to their respective objects.

Input Details

While the products may vary, valid input must follow basic formatting rules. Each product must include the following details for each of the five categories below, separated by a comma:

name, quantity, year, grade

For name, "coin type" may be used for coins, "title" may be used for novels, and "character" may be used for action figures.

A sixth category would be required for both novels and action figures:

publisher or manufacturer

A product class serves as the base class while the three current products are derived from the product class. Discrepancies such as how coins do not need to include this sixth category (unlike novels and action figures) can be addressed through inheritance.

Inventory File

The data file which initializes the inventory list must be formatted correctly. The input syntax is as follows:

C, 3, 2001, 65, Lincoln Cent
C, 10, 1913, 70, Liberty Nickel
N, 1, 1938, Mint, Superman, DC 
N, 2, 2010, Excellent, X-Men, Marvel
Z, 7, 2004, Exciting, Nightwish, Once
F, 9, 2012, Near Mint, Mikasa Ackerman, Good Smile
F, 1, 1999, Very Good, Squall Leonhart, Square Enix

The three letters C, N, and F represent coin, novel, and action figure respectively. Although the fifth entry is formatted correctly, that line will be ignored, as it (Z) does not map to any of the current products. 

Error Handling: Any incorrect formatting within a file that contains some correct formatting will be ignored. If all entries are incorrectly formatted, an error message will be printed to the user.

Customer File

Customers are listed in a similar, yet slightly simpler manner. The two fields are entered and separated by a comma - the customer ID and customer name. 

009, Alexa Romana
456, Erwin Valentov
777, Kim

Error Handling: If there are duplicate names, the customer ID must be unique to each case. 

Transaction File

Valid entries within this input file must start with S (sell), B (buy), D (display), or C (customer). For sell and buy transactions, S or B must be followed by and customer ID and the product description. C must be followed by a customer ID while D followed by nothing suggests a display command. 

S, 456, F, 9, 2012, Near Mint, Mikasa Ackerman, Good Smile
B, 009, M, 1913, 70, Liberty Nickel
C, 777
D
X, 999, Z, 7, 2004, Exciting, Nightwish, Once
S, 000, Q, 2112, Radical, MacBook, Apple
H

Error Handling: If some entries are invalid (such as the last four lines), those lines will be ignored. If all entries are invalid, an error message will be printed to the user. 


Class Diagram

inventory tracker class diagram



Design

Store

Store interfaces with main to parse data from input files while serving as a container for ProductFactory, CustomerHouse, and ActionStation.

Data members:

-inventory_: ProductFactory

ProductFactory holding all of the Products read from input file

-customerList_: CustomerHouse

CustomerHouse holding all of the Customers read from input file

-commands_: ActionStation

ActionStation holding all of the Transactions read from input file

The methods are described below in UML notation for accessibility:

+stockInventory(product: string) : void

-- reads contents of inventory input file
-- requests inventory_ to create Product objects
-- adds Product objects to inventory_

+inviteCustomers(customer: string) : void

-- reads contents of customer input file
-- adds Customer objects to customerList_

+doBusiness(transaction: string) : void

-- reads contents of transaction input file
-- generates an interaction between inventory_ and customerList_ or prints data to output

Declared in the header file as a friend in order to access private data members

ProductFactory

ProductFactory creates, removes, and retrieves product objects stored in binary search trees as collections within a hash table data member.

Data member:

-hashTable_: BST [ ]

Array holding binary search trees

The methods are described below in UML notation for accessibility:

Constructor

+ProductFactory( );

+create(key: char, quantity: int, description: string) : Item*

-- Calls hashFunction and uses the returned index
-- Calls insertItem to store a Product* object in hashTable_
-- Used for callers to create a dynamically allocated Comparable

+remove(description: string) : Item*

-- Calls hashFunction and uses the returned index
-- Calls deleteItem to remove a Product* object in hashTable_

+get(description: string) : Item*

-- Retrieves a Product*

-hashFunction(key: char) : int

-- Generates an index integer for the caller

-insertItem(key: char, item: Item*&) : void

-- Calls hashFunction and uses returned index to store a Product* object in hashTable_

-removeItem(key: char, item: Item*&) : Item*

-- Calls hashFunction and uses returned index to remove a Product* object in hashTable_

CustomerHouse

CustomerHouse creates, removes, and retrieves customer objects stored in a hash table for quick lookup and a binary search tree in order to include sort functionality.

Data member:

-sortedList_: BST [ ]

BST holding Customer* objects for sorted printing

-quickLookup_: Customer* [ ]

Array holding Customer* objects for quick lookup

The methods are described below in UML notation for accessibility:

Constructor

+CustomerHouse( );

+create(description: string) : Item*

-- Calls insertItem to store a Customer* object in hashTable_
-- Used for callers to create a dynamically allocated Comparable

+remove(id: int) : void

-- Calls hashFunction and uses the returned index to remove a Customer* object in hashTable_

+get(id: int) : Item*

-- Retrieves a Customer*

+getTransactions(id: int) : string

-- Returns all transactions for an individual Customer in string format

+cBuy(id: int, product: Item*) : void

-- Adds a Product to or increases quantity of Product in Customer object's purchases_ vector

+cSell(id: int, product: Item*) : void

-- Adds a Product to or increases quantity of Product in Customer object's sales_ vector

-hashFunction(id: int, itr: int) : int

-- Generates an index integer for the caller (itr represents the current iteration after a collision)

-addCustomer(id: int, cstm: Customer*&)

-- Calls hashFunction and uses returned index to store a Customer* object in hashTable_

Actionstation

ActionStation holds a hash table of Transaction objects, allowing for polymorphism. Each operation calls a method based on one of the derived Transaction classes.

Data member:

-actionTable_: Transaction* [ ]

Array holding Transaction* objects

The methods are described below in UML notation for accessibility:

Constructor

+ActionStation( );

Destructor

+~ActionStation( );

+transact(description: string, pf: ProductFactory&, ch: CustomerHouse&) : void

-- Parses a key from transaction description (command), passes the remaining substring in a call to use, viewInv, or viewCus

-use(key: char, subDescription: string, pf: ProductFactory&, ch: CustomerHouse&) : void

-- Helper method for transact
-- Calls a specific method contingent on a key triggering its overridden version within one of the derived classes

-viewInv(pf: ProductFactory&) : void

-- Helper method for transact
-- Calls a specific method contingent on a key triggering its overridden version within one of the derived classes

-viewCus(ch: CustomerHouse&) : void

-- Helper method for transact
-- Calls a specific method contingent on a key triggering its overridden version within one of the derived classes

BST

BST is the binary search tree class that holds Item* objects.

Data member:

-rootPtr_ : Node*

A pointer to the root node

The methods are described below in UML notation for accessibility:

Constructor

+BST( );

Destructor

+~BST( );

+insert(item: Item*) : bool

-- Calls add to create a node with the Item value passed with a quantity of 1 or increases quantity by 1

+remove(item: Item*) : bool

-- If the Comparable is present, decreases quantity by 1 or removes the node if the quantity is 1

+retrieval(key: string) : Item*

-- Finds and returns an Item within BST if present

+print( ) : void

-- Prints a table of Items with associated quantities in BST using inorder

BST::Node

Node is a nested struct within BST

Data members:

-item_ : Item*

Item data storage

-leftChild_ : Node*

A pointer to the left child of the current node

-rightChild_ : Node*

A pointer to the right child of the current node

The method is described below in UML notation for accessibility:

Constructor

+Node( );

Item

Item is the base class for all products and the single customer class.

Data members:

-key_ : char

The item key

-quantity_ : int

The item quantity

The methods are described below in UML notation for accessibility:

Constructor

+Item( );

Destructor

+~Item( );

+operator<(rhs: Item&) : bool

+operator==(rhs: Item&) : bool

+build(key: char, description: string) : Item*

-- Creates a new Item*
-- Receives a description for the Item that is parsed for attributes

+getItem( ) : string

-- a string containing the Comparable description is returned. Each detail is separated by a comma allowing the entire Comparable description to be presented on one line

+isEmpty( ) : bool

-- returns true if quantity_ equals 0, false otherwise

+reduce( ) : void

-- decreases the quantity of a Item by 1 if quantity >= 1

+increase( ) : void

-- increases the quantity of a Comparable by 1

Product

Product is a derived class based on Item and the base class for all products.

Data members:

-name_ : char

The name of this product

-year_ : string

The year in which this product was released

The methods are described below in UML notation for accessibility:

Constructor

+Product( );

Destructor

+~Product( );

+operator<(rhs: Item&) : bool

+operator==(rhs: Item&) : bool

+build(key: char, description: string) : Product*

-- Creates a new Product*
-- Receives a description for the Product that is parsed for attributes

+getItem( ) : string

-- a string containing the Product description is returned. Each detail is separated by a comma allowing the entire Product description to be presented on one line

Coin

Coin is a derived class based on Product.

Data members:

-type_ : string

The name or description of this product

-grade_ : int

A measure of quantity within its product category

The methods are described below in UML notation for accessibility:

Constructor

+Coin( );

Destructor

+~Coin( );

+operator<(rhs: Item&) : bool

+operator==(rhs: Item&) : bool

+build(key: char, description: string) : Coin*

-- Creates a new Coin*
-- Receives a description for the Coin that is parsed for attributes

+getItem( ) : string

-- a string containing the Coin description is returned. Each detail is separated by a comma allowing the entire Product description to be presented on one line

Novel

Novel is a derived class based on Product.

Data members:

-title_ : string

The name or description of this product

-grade_ : string

A measure of quantity within its product category

-publisher_ : string

The publisher name for this product

The methods are described below in UML notation for accessibility:

Constructor

+Novel( );

Destructor

+~Novel( );

+operator<(rhs: Item&) : bool

+operator==(rhs: Item&) : bool

+build(key: char, description: string) : Novel*

-- Creates a new Novel*
-- Receives a description for the Novel that is parsed for attributes

+getItem( ) : string

-- a string containing the Novel description is returned. Each detail is separated by a comma allowing the entire Product description to be presented on one line

ActionFigure

ActionFigure is a derived class based on Product.

Data members:

-character_ : string

The character name for this action figure

-grade_ : string

A measure of quantity within its product category

-manufacturer_ : string

The manufacturer name for this product

The methods are described below in UML notation for accessibility:

Constructor

+ActionFigure( );

Destructor

+~ActionFigure( );

+operator<(rhs: Item&) : bool

+operator==(rhs: Item&) : bool

+build(key: char, description: string) : ActionFigure*

-- Creates a new ActionFigure*
-- Receives a description for the ActionFigure that is parsed for attributes

+getItem( ) : string

-- a string containing the ActionFigure description is returned. Each detail is separated by a comma allowing the entire Product description to be presented on one line

Customer

ActionFigure is a derived class based on Product.

Data members:

-firstName_ : string

The first name of this customer

-lastName_ : string

The last name of this customer

-id_ : int

The unique three-digit Customer ID

-transactions_ : string [ ]

Array/vector containing all Customer transactions

The methods are described below in UML notation for accessibility:

Constructor

+Customer( );

Destructor

+~Customer( );

+operator<(rhs: Item&) : bool

+operator==(rhs: Item&) : bool

+build(description: string) : Customer*

-- Creates a new Customer*
-- Receives a description for the Customer that is parsed for attributes

+getItem( ) : string

-- Prints all transactions for an individual Customer

+getInfo( ) : string

-- a string containing the Customer description is returned. Each detail is separated by a comma allowing the entire Customer description to be presented on one line

+addS(product: Item*) : void

-- adds a Product to transactions_, marking 'S' for a Store Sale during a Customer buy

+addS(product: Item*) : void

-- adds a Product to transactions_, marking 'B' for a Store Buy during a Customer sale

Transaction

Transaction is the base class for all objects with operations that handle the interactions between ProductFactory (inventory) and CustomerHouse (customers).

The methods are described below in UML notation for accessibility:

Constructor

+Transaction( );

Destructor

+~Transaction( );

+sell(subDescription: string, pf: ProductFactory&, ch: CustomerHouse&) : void

-- a string containing the Transaction description is read and parsed. The details of the transaction will generate an interaction between ProductFactory and CustomerHouse
-- a Product is bought by a Customer and sold by Store

+buy(subDescription: string, pf: ProductFactory&, ch: CustomerHouse&) : void

-- a string containing the Transaction description is read and parsed. The details of the transaction will generate an interaction between ProductFactory and CustomerHouse
-- a Product is sold by a Customer and bought by Store

+display(pf: ProductFactory&) : void

-- Commands ProductFactory to print the contents of its inventory, skipping any items with a quantity of 0

+customer(id: int, ch: CustomerHouse&) : void

-- Commands CustomerHouse to call the Customer matching the id passed to call the Customer to print out all transactions in chronological order

+history(ch: CustomerHouse&) : void

-- Commands CustomerHouse to print all transactions by every Customer, listed in alphabetical order by first name

Sell

Sell is a derived class of Transaction that handles interactions involving products sold to customers; these products are removed from Store’s inventory.

The methods are described below in UML notation for accessibility:

Constructor

+Sell( );

Destructor

+~Sell( );

+sell(subDescription: string, pf: ProductFactory&, ch: CustomerHouse&) : void

-- a string containing the Transaction description is read and parsed. The details of the transaction will generate an interaction between ProductFactory and CustomerHouse
-- a Product is bought by a Customer and sold by Store

Buy

Buy is a derived class of Transaction that handles interactions involving products sold by customers; these products are added to Store’s inventory.

The methods are described below in UML notation for accessibility:

Constructor

+Buy( );

Destructor

+~Buy( );

+buy(subDescription: string, pf: ProductFactory&, ch: CustomerHouse&) : void

-- a string containing the Transaction description is read and parsed. The details of the transaction will generate an interaction between ProductFactory and CustomerHouse
-- a Product is sold by a Customer and bought by Store

Display

Display is a derived class of Transaction that prints all of the products currently in Store’s inventory.

The methods are described below in UML notation for accessibility:

Constructor

+Display( );

Destructor

+~Display( );

+display(pf: ProductFactory&) : void

-- Commands ProductFactory to print the contents of its inventory, skipping any items with a quantity of 0

CustTransaction

CustTransaction is a derived class of Transaction that prints a single customer’s list of transactions.

The methods are described below in UML notation for accessibility:

Constructor

+CustTransaction( );

Destructor

+~CustTransaction( );

+customer(id: int, ch: CustomerHouse&) : void

-- Commands CustomerHouse to call the Customer matching the id passed to call the Customer to print out all transactions in chronological order

History

History is a derived class of Transaction that prints every transaction for all customers.

The methods are described below in UML notation for accessibility:

Constructor

+History( );

Destructor

+~History( );

+history(ch: CustomerHouse&) : void

-- Commands CustomerHouse to print all transactions by every Customer, listed in alphabetical order by first name