Goal

The goal of both Assignments #5 and #6 will be to explore two very different ways of implementing the same behaviour. This will include implementing five new product categories : dairy, coffee/tea, bakery, meat and miscellaneous goods, and classifying every product into one of these categories. You will also implement two separate types of behaviour: one based on whether a product is perishable or non-perishable, and one based on whether a product is taxable or non-taxable. Perishable products have a short lifetime before they expire (spoil), and non- perishable ones have a longer default lifetime of two years. Taxable products must have Ontario tax (13%) added to their price at the time of purchase, and non-taxable ones have no tax imposed on them.

In this assignment, you will modify your inventory management program from any previous assignment, or from the base code, to implement an inheritance hierarchy of product classes, along with polymorphic functions. You will implement the two behaviours outlined above using the Strategy design pattern and behaviour classes . You will also be using an STL container to hold one of the collections.

Learning Objectives

  • create an inheritance hierarchy, with polymorphism
  • practice the implementation of a more complex design pattern
  • use containers and iterators from the STL

Instructions:

1. From previous assignments:

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

From Assignment #1:

  • implement the product purchase feature, using the Purchase and PurchArray classes

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: Most of the functionality in this assignment is not compatible with Assignment #5 , because the implementation is very different. It is strongly recommended that you begin from your Assignment #4 code and copy over selected portions of the functionality from Assignment #5, only as needed.

2. Create a product hierarchy

You will create five new product category classes, organized in a hierarchy derived from the Product class.

Note: Every product in the inventory management program will be an object of one of these five product category classes. There will be no instances of the Product class anymore.

You will modify the Product class as follows:

  • add three new data members: manufactured date and expiry date , which are both Date objects (described in a later step of this assignment), and lifespan , which is the number of days that a product is safe
  • modify the constructor to initialize the manufactured date and the lifespan from values passed in as parameters
  • add two member functions: computeTax and computeExpDate
  • the computeTax function takes no parameters and returns the amount of tax to be paid on the product
  • the computeExpDate function computes and sets the products expiry date
  • both of these member functions will be implemented in this class

The new product category classes will be derived directly from Product:

  • the Dairy class
  • the CoffeeTea class
  • the Bakery class
  • the Meat class
  • the MiscGoods class

Every new class must provide a constructor that invokes the base class constructor with the correct parameters. You will provide sufficient datafill for the different types of products. There will be no Product objects in the program. This means that you must change the existing product initialization function so that a variety of objects of the different category classes (Dairy, CoffeeTea, Bakery, Meat and MiscGoods) are created. You should still have at least 20 products in total.

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

3. Create a behaviour hierarchy

You will create two new abstract behaviour classes, and four new concrete behaviour classes.

The taxation behaviour classes will work as follows:

  • the TaxationBehaviour class will be abstract and contain the computeTax member function
  • both the Taxable and NonTaxable classes will be concrete and derived from TaxationBehaviour
  • both the Taxable and NonTaxable classes will provide an implementation for computeTax
  • the computeTax function will take in a price as parameter and return the amount of tax to be imposed
    • for taxable products, the amount of tax is computed by multiplying the price with a constant representing the tax rate for Ontario (13%)
    • for non-taxable products, the amount of tax is zero (there is no tax on non-taxable products)

The expiration behaviour classes will work as follows:

  • the ExpirationBehaviour class will be abstract and contain the computeExpDate member function
  • both the Perishable and NonPerishable classes will be concrete and derived from ExpirationBehaviour
  • both the Perishable and NonPerishable classes will provide an implementation for computeExpDate
  • the computeExpDate function will take in a manufactured date and a lifespan as parameters and return the expiry date, which is the sum of the two
    • for perishable products, the expiry date is the sum of the products manufactured date and lifespan
    • for non-perishable products, the expiry date is the sum of the products manufactured date and a program- wide default lifespan value (you can define this using a constant set to 730 days, which is two years)

The computeTax and computeExpDate functions on the behaviour classes will be polymorphic. You must implement these functions using polymorphism.

Note: Implementing this functionality by checking the types of classes, rather than using polymorphism, will result in the loss of all the marks for polymorphism and behaviour classes.

4. Modify the product classes to use the behaviour classes

You will modify the Product classes to use the behaviour classes:

  • the Product class will contain a pointer to a TaxationBehaviour object and a pointer to a ExpirationBehaviour object
  • all product category class constructors will initialize the behaviour pointers as follows:
    • the Dairy class has an expiration behaviour of perishable and a taxation behaviour of non-taxable
    • the CoffeeTea class has an expiration behaviour of non-perishable and a taxation behaviour of taxable
    • the Bakery class has an expiration behaviour of perishable and a taxation behaviour of taxable
    • the Meat class has an expiration behaviour of perishable and a taxation behaviour of non-taxable
    • the MiscGoods class has an expiration behaviour of non-perishable and a taxation behaviour of non-taxable
  • all product category class constructors must invoke the Product class computeExpDate function to initialize the expiry date
  • the computeExpDate function in the Product class invokes the same function on the expiration behaviour object and sets the expiry date to the returned value
  • the computeTax function on the Product class invokes the same function on the taxation behaviour object
  • the computeExpDate function in the Product class must be called from every product category class constructor
  • the computeTax function in the Product class must be called whenever a product is purchased, and the tax amount must be added to the amount that the customer pays

Note: You must use overloaded operators on the Date class to compute the expiry date.

5. Implement a new date class with overloaded operators

You will implement a new Date class, with overloaded operators, as described in Assignment #5. For more details, see the Assignment #5 description.

6. Modify other program features

You will modify some of the existing features to work with the new Product classes, as described in Assignment #5. For more details, see the Assignment #5 description.

7. Use the STL list class and iterators

You will remove the CustArray class from the program, and you will store the customer collection in an STL list container. This will require some minor changes in several places in the program, including the use of STL iterators to traverse the customer collection.

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 from the C++ standard template library (STL), except where explicitly indicated
  • 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.