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 federal and Ontario harmonized 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 multiple inheritance and polymorphism

Learning Objectives

  • create an inheritance hierarchy, including multiple inheritance, with polymorphism
  • practice implementing overloaded operators

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.

If you are starting from Assignment #3, you can continue using the linked list collection class.

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. Create a product hierarchy

You will create several new classes, organized in a hierarchy derived from the Product class. Two new classes (Perishable and NonPerishable) will contain behaviour to compute a products expiry date (also called best before date). Two other new classes (Taxable and NonTaxable) will determine what amount of tax must be added to a products price when it is purchased. Five additional new classes will represent product categories

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, because it will be abstract.

You will modify the Product class as follows:

  • add two new data members: manufactured date and expiry date , which are both Date objects (described in a later step of this assignment)
  • modify the constructor to initialize the manufactured date from a year, month, and day 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
  • neither of these two member functions will be implemented in this class

The new behaviour-like classes will be defined as follows:

  • the Perishable class:
    • is derived from the Product class
    • contains one additional data member: lifespan , which is the number of days that a product is safe, i.e. the number of days between the manufactured date and the expiry date
  • the NonPerishable class is derived from the Product class and contains no new data members
  • the Taxable class is derived from the Product class and contains no new data members
  • the NonTaxable class is derived from the Product class and contains no new data members

The new product category classes will be defined as follows:

  • the Dairy class is derived from both the Perishable class and the NonTaxable class
  • the CoffeeTea class is derived from both the NonPerishable class and the Taxable class
  • the Bakery class is derived from both the Perishable class and the Taxable class
  • the Meat class is derived from both the Perishable class and the NonTaxable class
  • the MiscGoods class is derived from both the NonPerishable class and the NonTaxable class

Every new class must provide a constructor that initializes its own data member(s) and invokes all its base class constructor(s) with correct parameters.

You will provide sufficient datafill for the different types of products. There will be no Product objects in the program, and there will be no objects of the behaviour-like classes. 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. Implement the polymorphic functions

The computeTax and computeExpDate functions on the product classes will be polymorphic. Only the Taxable and NonTaxable classes will implement the computeTax function, and only the Perishable and NonPerishable classes will implement the computeExpDate function. 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, so a deduction of a minimum of 30 marks.

The computeExpDate function computes and initializes the products expiry date . It behaves as follows:

  • it is implemented on the Perishable and NonPerishable classes
  • for perishable products, the expiry date is the sum of the products manufactured date and its 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)
  • this function must be called from the constructors of both the Perishable and NonPerishable classes

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

The computeTax function returns the amount of tax to be imposed on the product. The function behaves as follows:

  • it is implemented on the Taxable and NonTaxable classes
  • for taxable products, the amount of tax is computed by multiplying the product price with a constant representing the HST tax rate for Ontario (13%)
  • for non-taxable products, the amount of tax is always zero (there is no tax on non-taxable products)
  • this function must be called whenever a product is purchased, and the tax amount must be added to the amount that the customer pays

4. Implement a new date class with overloaded operators

You will implement a new Date class, with three integer data members representing the day, month and year, as we saw in class. You will implement three overloaded operators on the Date class:

Operator Parameter Functionality
+= int numDays Add numDays to this date
+ int numDays Return a new Date object that is the sum of this and numDays
> or < Date& other Returns a boolean indicating whether this date is greater than
or less than other

Notes:

  • You will implement either the < or the > operator, depending on how you add products to the product collection
  • They must be called in the program in order to earn marks (hint: one of the + or += operators calls the other)
  • You must enable cascading everywhere appropriate
  • You can reuse and add to the code from the Date class that we worked on in class

5. Modify other program features

You will modify some of the existing features to work with the new Product classes:

  • adding a product to the product collection
    • rather than adding products in ascending (increasing) number of units, you will add them in ascending order of expiry date ; you must use an overloaded operator on the Date class for this
    • if you are working from Assignment #3 or later, you can keep the reorganizing of the product collection by order of units; however, the initial collection of products (before any purchases or adding inventory) must be ordered by expiry date
  • add a new product feature
    • modify the add a new product feature so that it prompts the user for the product category and creates a product of the correct concrete class
  • print inventory feature
    • modify the print inventory feature so that it prints out each products expiry date. This will require a toString function on the Date class

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)
  • 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.