Goal

You will modify your inventory management program from either Assignment #2 or from the base code to store the products in a linked list and to implement one new feature.

Learning Objectives

  • gain additional experience with dynamically allocated memory in C++ using linked lists

Instructions:

1. From previous assignments:

You will need to implement the following features from previous assignments.

From Assignment #1:

  • implement the product purchase feature
  • the implementation of the Purchase and PurchArray classes is optional ; you can implement the product purchase feature using two primitive arrays in the Customer class instead

For more details, see the Assignment #1 description.

From Assignment #2:

  • modify the program to dynamically allocate all data objects, specifically Product and Customer objects
  • modify the product and customer collection classes to contain an array of pointers to objects
  • explicitly deallocate all dynamically allocated memory; memory leaks will be penalized

For more details, see the Assignment #2 description.

Note: Insufficient or incorrect datafill means that your assignment cannot be adequately tested; this may incur deductions of up to 100% of the assignment

2. Replace the ProdArray class with a new linked list class

You will create a new linked list class called ProdList, which will hold the collection of products as a linked list instead of an array. Products will be stored in ascending (increasing) order of the number of units . The linked list will be implemented as a doubly linked list based on the format that we saw in class, with each node holding a pointer to a Product object.

The ProdList class should:

  • hold a pointer to the head of the list, but no pointer to the tail of the list
  • provide an add function that takes a Product pointer and adds the product in its correct place in the list
  • provide a remove function that takes a Product pointer and removes the corresponding product from the list
  • provide a reorg function that sorts the product list in ascending order of number of units; this function must be called whenever the number of units of a product is modified, for example when inventory is reduced (when a product is purchased) or when inventory is increased; you can implement a simple bubble sort, or any simple sorting algorithm for this
  • provide additional functions as required (hint: a find function may be useful here)
  • manage its memory to avoid memory leaks

Notes:

  • DO NOT use dummy nodes! Every node in the list must correspond to a product.
  • You will modify your program to use a ProdList object instead of a ProdArray object to hold the products.
  • All classes will continue to interact with the ProdList class the same way they did with the ProdArray class. The changes to the rest of the classes should be minimal.
  • The order in which your datafill is added to the list must test all cases: adding to the front, back, middle, etc.
  • Your list must be stored in ascending order of product units at all times

3. Modify the print inventory feature

Printing out the linked list poses a new challenge in maintaining our existing design, specifically the separation of the UI and collection classes. We are not permitted to print out data from inside the collection class, since a collection class should not know how to interact with the outside world. We also cannot allow the UI class to traverse the product collection in order to print it to the screen, since that would require knowledge by the UI class of the internal configuration of the list, including the Node class, which would also violate encapsulation rules.

Our solution here will be to implement a formatting function on the ProdList class. This function will have the prototype: void toString(string& outStr) where the outStr parameter is the result of the function concatenating all the product data formatted into one long string. This long string will contain all product data found by traversing the linked list in the forward direction (from the front to the back), followed by all the same product data found by traversing the linked list in the backward direction (from the back to the front). The UI class will invoke the formatting function on the ProdList object, and then output the resulting formatted string to the screen.

Note:

  • DO NOT have your UI class traverse the linked list! DO NOT print to the screen from the list class!

4. Implement the remove product feature

You will implement the remove product feature, which is available from the admin menu. This feature prompts the user to enter a product id, and the corresponding product is removed from the list of products.

Constraints

  • your program must follow the existing design of the base code, including the encapsulation of control, UI, entity and array object functionality
  • do not use any classes or containers or algorithms from the C++ standard template library (STL)
  • do not use any global variables or any global functions other than main
  • do not use structs; use classes instead
  • objects must always be passed by reference, not by value
  • your classes must be thoroughly documented
  • all basic error checking must be performed
Academic Honesty!
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.