Write C++ classes that manage the inventory of a small store.
Product: For each product, you should store the following info:
product name (i.e. “Apple iPhone 3GS 8GB”, may contain spaces in it)
locator (string with no spaces, used to locate product, not necessarily unique)
quantity (how many of this product in stock, greater than or equal to 0)
price (in dollars and cents, greater than 0)
Note: For a given product, the product name AND locator together must be unique. So you may have two entries for “iPhone 5c” if one has “box3” for the locator and the other has “shelf12”.
When a product inventory object is created, it should dynamically allocate an array of Product, using a constructor parameter to determine the size. (You should also implement a destructor).
You should implement the following operations over the electronics store inventory:
addProduct: takes a product and adds it to the inventory. If the inventory is full, it should call the resize function first (see below). If a product with the same name and locator are already in the inventory, the add should fail and return false. If the quantity or price are invalid, it should fail and return false.
removeProduct: takes a product name and locator and removes any matching entry for that product from the inventory. Returns true if a product was removed.
showInventory: displays a listing of the store inventory to the screen, one product entry per line. Output locator, then quantity, then price, then product name.
sortInventory: reorders the products in the list, using the < (or >) operator over the products (see instructions below) (does not display them).
getTotalQuantity: returns the total number of units of all of the products in the inventory.
resize: internal function that doubles the size of the inventory array (recall duplicateArray). Allocates a new array, and copies all the existing products to it. Be sure to clean up.
Create classes for Product and ProductInventory with appropriate header files.
Implement methods in the ProductInventory class to complete the operations described above.
You may add other private, helper, functions if you want.
Implement functions in the Product class to:
set and get all instance variables (make instance variables private)
overload ==, <,and > operators
for < and > use product name and when the product names are the same, use the locator.
for ==, two products are equal if they have the same product name and locator values.
You should implement two constructors for the Product class: one that takes no arguments (quantity and price are 0, product name and locator are empty strings), and one that takes a value for each of the four member variables.
The main function should be a driver program that tests the functionality of the Product and ProductInventory classes. See the website for a driver program that MUST work with your code (without changing the driver program). I recommend expanding the driver to do more complete testing of your code. Even if your program works correctly with the driver it may still have bugs not exposed by the driver.
Do not add extra I/O to the class functions. All the testing should happen in the driver.
It is not our intention to break the school's academic policy. Projects posted are only used as a reference
and should not be submitted as is. We are not held liable for any misuse of the solutions.
Please see the frequently asked questions page
for further questions and inquiries.
Kindly fill out the form.
Please provide a valid email address and we'll get back to you in less than 24 hours.
We will be sending an invoice through PayPal upon confirmation.
We are a non profit organization however we need an amount to keep this organization running,
and to be able to complete our research and development.