// Lab Test 2 - v4 (for L4) // In this lab, you are given an application program, t3-4.cpp. You must supply files // "Inventory.h" and "Inventory.cpp" that this program uses. You need only include the // member methods used in this program. The comments in the application program explain // the behaviour of the class you are writing. You are strongly encouraged to make additions // to t3-4.cpp to ensure that your class works properly in all circumstances, including // throwing exceptions as advertized. // You must call your files "Inventory.h" and "Inventory.cpp" and submit both as assignment // #8 using the submit program provided. // Hints: // 1. Be sure to use the "const" keyword where appropriate. // 2. Date.h and Date.cpp (that you used in lab test #2) are provided so that you can // ensure that you use the proper syntax in setting up your class. (Do not include the // Date class your class!) // 3. It is not necessary to create any arrays in this class. (You may do so if you choose, // but as the most efficient implementation does not require arrays, you will not get // full marks if you use arrays.) #include "stdstuff.h" #include "Inventory.h" void realMain () { // Create three items. part1 is "hammer". There are currently 25 "hammer"s in // the warehouse. part2 is "nail". There are currently 1050 in the warehouse. // part3 is "hook". There are currently no hooks in the warehouse. // If the quantity on hand (here 25 and 1050) is negative an invalid_argument // exception is thrown. Inventory part1("hammer", 25), part2("nail", 1050), part3("hook"); // Parts are sold to customers and this shows the number sold. In this case, 8 // hammers and 425 nails have been sold. // If the quantity sold is negative or will cause the number of items left in the // inventory to become negative an invalid_argument exception is thrown. part1.sell(8); // 8 hammers have been sold, so there are now 17 left part2.sell(425); // 425 nails have been sold, so there are now 625 left // If there are less than the number of items specified remaining in the inventory, // new stock is ordered and added to the inventory. The stock is always increased // by 20 items. // (If there are the given number or more items remaining in the inventory, // nothing happens.) // If the number of items specfied is negative, an invalid_argument exception is thrown. // The number of items ordered and added to the inventory is explained above. part1.stockUp(20); // as there are 17 hammers left, 20 are added to the inventory. part2.stockUp(500); // as there are 625 nails remaining, none are ordered. part3.stockUp(10); // as there are no hooks, 20 are added to the inventory. // This gives the current number of items on hand. This will print 37, 625 and 20. cout << "Number of part1s in inventory is: " << part1.getStock() << ".\n"; cout << "Number of part2s in inventory is: " << part2.getStock() << ".\n"; cout << "Number of part3s in inventory is: " << part3.getStock() << ".\n\n"; // This gives the names of the items. It should print "hammer", // "nail" and "hook". cout << "part1 is " << part1.getItem() << ".\n"; cout << "part2 is " << part2.getItem() << ".\n"; cout << "part3 is " << part3.getItem() << ".\n\n"; // Now 25 more hammers and 10 hooks have been sold. // If the quantity sold is negative or will cause the number of items left in the // inventory to become negative an invalid_argument exception is thrown. part1.sell(25); // 25 hammers have been sold part3.sell(10); // 10 hooks have been sold // This gives the total number of items sold to date. This should print 33, 425 and 10. cout << part1.totalSold() << " part1s have been sold.\n"; cout << part2.totalSold() << " part2s have been sold.\n"; cout << part3.totalSold() << " part3s have been sold.\n\n"; // This prints the lowest number of items in the inventory to date. This should print // 12, 625 and 0. cout << "The minimum number of part1 in the inventory to date is: "; part1.printMinInventory(); cout << ".\nThe minimum number of part2 in the inventory to date is: "; part2.printMinInventory(); cout << ".\nThe minimum number of part3 in the inventory to date is: "; part3.printMinInventory(); cout << ".\n\n"; } int main () { try { realMain (); } catch (exception &e) { // catches all uncaught exceptions cout << "\nException <" << e.what() << "> occurred.\n"; } pause (); return 0; }