When disaster hits a populated area, the most critical task is to provide immediately affected people with what they need as quickly and as efficiently as possible.
This project completes an application that manages the list of goods that need to be shipped to the disaster area. The client application tracks the quantity of items needed, tracks the quantity on hand, and stores the information in a file for future use.
The types of goods that need to be shipped are of two categories;
- Non-Perishable products, such as blankets and tents, which have no expiry date. We refer to products in this category as Product objects.
- Perishable products, such as food and medicine, that have an expiry date. We refer to products in this category as Perishable.
To complete this project you will need to create several classes that encapsulate your solution.
OVERVIEW OF THE CLASSES TO BE DEVELOPED
The classes used by the client application are:
- Date: A class to be used to hold the expiry date of the perishable items.
- ErrorState: A class to keep track of the error state of client code. Errors may occur during data entry and user interaction.
- Product: A class for managing non-perishable products.
- Perishable: A class for managing perishable products. This class inherits the structure of the "Product" class and manages an expiry date.
- iProduct: An interface to the Product hierarchy. This interface exposes the features of the hierarchy available to the client application. Any "iProduct" class can
- read itself from or write itself to the console
- save itself to or load itself from a text file
- compare itself to a unique C-string identifier
- determine if it is greater than another product in the collating sequence
- report the total cost of the items on hand
- describe itself
- update the quantity of the items on hand
- report its quantity of the items on hand
- report the quantity of items needed
- accept a number of items
- Using this class, the client application can
- save its set of iProducts to a file and retrieve that set later
- read individual item specifications from the keyboard and display them on the screen
- update information regarding the number of each product on hand
THE CLIENT APPLICATION
The client application manages the iProducts and provides the user with options to
- list the Products
- display details of a Product
- add a Product
- add items of a Product
- update the items of a Product
- delete a Product
- sort the set of Products
MILESTONE 4: THE IPRODUCT INTERFACE
The iProduct class is an interface that exposes the Product hierarchy to client applications. This class contains only pure virtual functions and cannot be instantiated.
Save your definition of the iProduct interface in a header file named iProduct.h. The interface should be defined in the ama namespace.
The definition of your iProduct interface includes the following pure virtual member functions (these functions will be implemented in the derived classes):
- ostream& write(ostream& os, int writeMode) const: This function writes the content of the current instance in the stream received as the first parameter. The second parameter signals the format of the output (see class Product for details).
- istream& read(istream& is, bool interractive): This function reads data from the stream, and stores it in the attributes. Depending on the second parameter, this function prompts the user asking for values, or doesn't interact with the user (see class Product for details).
- bool operator==(const char* sku) const: This query returns true if the string specified in the parameter is the same as the SKU of the current instance; false otherwise.
- double total_cost() const: This query returns the total cost of all available units of product, including tax.
- int qtyNeeded() const: This query returns the how many units of product are needed.
- int qtyAvailable() const: This query returns the how many units of product are available.
- const char* name() const: This query returns the address of the string storing the name of the product.
- int operator+=(int qty): This modifier receives an integer identifying the number of units to be added to the available quantity of product and returns the updated number of units on hand.
- bool operator>(const iProduct& other) const: This query returns true if the name of the current products is greater than the name of the iProduct received as parameter (according to how the string comparison functions define 'greater than'); false otherwise.
The interface should also define a virtual empty-body destructor (implement it as an inline function).
CHANGES IN PRODUCT MODULE
Update the Product module by doing the following:
- Include the iProduct.h header in Product.h.
- Change the Product class definition to publicly inherit from the interface iProduct.
- Update the prototype of the operator> to accept as parameter an un-modifiable reference to iProduct: bool operator>(const iProduct& other) const (make sure to update the prototype in the Product.cpp as well; do not change the implementation).
- Move all the constants you have defined in Product.h to iProduct.h (still in the ama namespace).
NOTE: See that the functions from the interface are already implemented in the Product class.
CHANGES IN UTILITIES MODULE
Modify the prototypes of the three helper operators from this module to accept as parameter references to iProduct instead of references to Product, like this:
- double& operator+=(double& total, const iProduct& prod)
- ostream& operator<<(ostream& out, const iProduct& prod)
- istream& operator>>(istream& in, iProduct& prod)
NOTE: The implementation of these operators should not change.
Declare and define the following function:
- iProduct* createInstance(char tag): This function is responsible to dynamically create instances in the Product hierarchy.
- If the parameter has the value 'N' or 'n', this function should dynamically create an object of type Product using the default constructor and return its address.
- If the parameter has any other value, this function should return null.