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”.
ProductInventory:
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.
Classes:
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.
Input/Output:
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. Posted solutions are meant to be 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 complete the form.
Please provide a valid email address and we will get back to you within 24 hours.
Payment is through PayPal, Buy me a Coffee
or Cryptocurrency.
We are a nonprofit organization however we need funds to keep this organization operating
and to be able to complete our research and development projects.