Question: c++ question: class InventoryItem (minimum implementation specified below) - This is the base class. Protected member data: item id (integer) and restocking (bool). Public static

c++ question:

class InventoryItem (minimum implementation specified below) - This is the base class.

  • Protected member data: item id (integer) and restocking (bool).
  • Public static data:
    • const integer (item id): initialize to 9999.
    • const bool (restocking): initialize to false.
  • Constructors
    • Default constructor: initialize item id and restocking using the default static data with member initializer syntax.
    • Non-default constructor: take 2 parameters.
  • Destructor: output "InventoryItem with restocking destroyed ..."
  • Public member functions:
    • mutator/accessor for restocking, item id.
    • Display: to show InventoryItem item id and restocking (true/false). item id must be displayed as a 4-digit integer with leading 0s if < 1000.

class Product: derived from InventoryItem class (minimum implementation specified below).

  • Private member data: name (string), quantity (integer) and price (double).
  • Public static data:
    • const string (name): "No Product".
    • const int (quantity): 0
    • const double (price): 0.99
  • Constructors (use member initializer syntax)
    • Default constructor: set member data to static data's default values above. Must explicitly invoke the base class' default constructor.
    • Non-default constructor: take five parameters (id, restocking, name, quantity and price). Must explicitly invoke the base class' non-default constructor.
  • Destructor: output "Product: , Name, quantity, price , restocking destroyed ...".
  • Public member functions:
    • accessors/mutators for name, quantity, price.
    • Display: invoke Display from base class, then display its own data. NOTE: If the product restocking is true somehow indicate it using "special effects" such as ***** or whatever effect you'd like.
    • Cost: take an integer as its only parameter representing the quantity (how many product to be sold) and return the total cost (price * quantity parameter).

class InventorySystem: (minimum implementation specified below). This class maintains an Inventory which is an array of pointers to InventoryItem which "point" to Product objects (Product class is derived from the base class InventoryItem)

  • Public static data
    • constant integer denoting array size (initialized to 512).
    • constant string as default value for store name ("My Store").
    • constant int as default value for product count ( 0 ).
    • constant string for Input file name.
    • constant string for Output file name.
  • Private member data
    • Store name
    • Product list (array of pointers to InventoryItem object whose size is the static data of value 512).
    • Product count (tracking how many items are currently stored in the array (or the inventory). This information should be used to control the loop whenever the Product list array is processed.
  • Constructors
    • Default constructor: set member data to the static default values as appropriate (must use member initializer syntax). Use a loop to explicitly initialize all pointers in the array to nullptr.
    • Non-default constructor: taking a string for store name. Do similar initialization as specified in default constructor.
  • Destructor: Finally our destructor has something to work for: de-allocate dynamic memory for individual Product objects in the array of pointers (up to product count elements).
  • Private member function:
    • FindInventoryItem: take an integer as item id and search through the array of pointers for a match. If found return the InventoryItem pointer (InventoryItem * is the return type of the function) to the found Product. Otherwise return nullptr.
  • Public member functions:
    • BuildInventory: read a text file (its name is the static data) containing Product records (one Product per line), dynamically allocate Product objects (by using Product's non-default constructor) and store the objects in the array product_list (the array of InventoryItem pointers). It should update product count member data accordingly to keep track of the number of inventory items in the system.
    • ShowInventory: display all Products in the inventory. Output must be properly formatted and aligned (using field width and floating data with 2 digits after decimal point). Hint: A loop to go thru the array of product list may dispolay only InventoryItem information. Extra work is needed to properly display both InventoryItem (base) and Products (derived objects) information.
    • UpdateInventory: ask for item id and quantity. Invoke the FindInventoryItem function. If such a Product is found display total cost and update Product object (reduce Product's quantity. If quantity becomes 0 update restocking to true).
    • Terminate: iterate through the array of pointers to write Product objects information to a text file (its name is the static data) in the same format as the input file's.
    • mutators/accessors for store name, store id and item count

Hint: Any file in this question, please use this:

433;Switch;71;399.99 654;iPhone 11;101;999.99 88;DVD Player;19;79.99 1734;PS5;12;499.99 35071;TV,177;899.99 2071;Laptop;65;1199.99 3070;RTX3070;65;699.99

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!