Taking Inventory

The StockItem class is designed to keep track of an individual item in the inventory, but we also need a way to keep track of all the StockItems in the store. So let's take a look at the next version of the class that serves that purpose in the inventory control application, Inventory. Figure 9.3 shows the header file for this version of the Inventory class, which is essentially identical to the last one from Chapter 6, except that we have added a ReorderItems function to allow us to generate a reorder report for all of the items in stock.

Figure 9.3. The next header file for the Inventory class (codeinvent20.h)
class Inventory
{
public:
    Inventory();

    short LoadInventory(std::istream& is);

    void StoreInventory(std::ostream& os);

    StockItem FindItem(std::string UPC);
    bool UpdateItem(StockItem Item);
    void ReorderItems(std::ostream& os);

private:
    Vec<StockItem> m_Stock;
    short m_StockCount;
};

Besides the default constructor, this class has several other member functions that we should discuss briefly, including those that we have already discussed in Chapter 6.

  1. LoadInventory reads data from an istream to create StockItem objects for the inventory.

  2. StoreInventory writes the current StockItem data to an ostream to save it for posterity.

  3. FindItem locates an item in the inventory by its UPC.

  4. UpdateItem updates the data for an item in the inventory.

  5. ReorderItems calls each item in the inventory and asks it to generate a line for the reordering report, which tells the user how many of each item need to be reordered from the distributor.

Susan had some questions about the arguments to LoadInventory and StoreInventory:

Susan: What are is and os? Why didn't you talk about them?

Steve: They're the names of the reference arguments of type istream and ostream, respectively, as indicated in the header file. They allow us to access the streams that we use to read data from the input file and write data to the output file.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset