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 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
PROJECT CLASS DIAGRAM
Figure: see image.
FILE STRUCTURE OF THE PROJECT
Each class has its own header (.h) file and its own implementation (.cpp) file. The name of each file is the name of its class.
Example: Class Date is defined in two files: Date.h and Date.cpp
All of the code developed for this application should be enclosed in the ama namespace.
MILESTONE 2: THE ERRORSTATE CLASS
The ErrorState class manages the error state of client code and encapsulates the last error message.
Any client can define and store an ErrorState object. If a client encounters an error, it can set its ErrorState object to an appropriate message. The client sets the length of the messagethe message must be a dynamically allocated string managed by this class.
The ErrorState object reports whether or not an error has occurred. The conversion to bool operator reports if the object holds a message (an error has occurred). If an error has occurred, the object can display the message associated with that error using the insertion operator (<<).
NOTE: This milestone does not use the Date class.
Implement the ErrorState class using following specifications below.
CLASS MEMBERS:
- Add to the class an attribute to store the address of the message, if any, in the current instance.
Add to the class the following public functions:
- explicit ErrorState(const char* errorMessage = nullptr): No/One argument constructor. This function receives the address of a C-style null terminated string that holds an error message.
- If the address is nullptr, this function puts the object in the safe empty state (the object is in the empty state when it stores nullptr in the attribute representing the message).
- If the address points to an empty string, this function puts the object in the safe empty state.
- If the address points to a non-empty message, this function allocates memory for that message and copies the message into the allocated memory. This function should not allocate more memory than it is necessary to store the string.
- ErrorState(const ErrorState& other) = delete: This class should not allow copying of any ErrorState object.
- ErrorState& operator=(const ErrorState& other) = delete: This class does not allow copy assignment.
- ~ErrorState(): This function de-allocates any memory that has been dynamically allocated by the current object.
- operator bool() const: this function return true if the current instance is storing a valid message (is not in the empty state).
- ErrorState& operator=(const char* pText): stores a copy the text received in the parameter. This function handles the parameter in the same way as the constructor.
- This is an overload of the assignment operatorthis function is not the copy assignment operator.
- Make sure that your code doesn't have memory leaks.
- void message(const char* pText): stores a copy the text received in the parameter. This function handles the parameter in the same way as the constructor.
- Make sure that your code doesn't have memory leaks.
- const char* message() const: this query returns the address of the message stored in the current object.
- If the object is in the safe empty state, this function returns nullptr.
Add the following helper function:
- operator<<: Prints the text stored in an ErrorState object to a stream. If the object is in the safe empty state, this function does nothing.
NOTE: You can add as many private members as your design requires. Do not add extra public members.
NOTE: See that some of the functions above have similar functionality. Reuse the code instead of duplicating it!