/* Inventory Shane Soult 3B Programmed to add, remove, show, and list inventory Input: command, part number Output: inventory, part number */ // MENU.CPP // // This program illustrates the use of simple one-character // commands. The program displays a menu, accepts a command // and executes it. The application is an embryonic // "Inventory Control System" which, at this stage of development, // only maintains a list of "inventory items" (integers). // Items are stored in an integer array. The "quantity" is // not supported -- it is set to 1 for all inventory items. // // Author: Bill Wares // #include #include #include #include // Declares toupper(ch) #include #include "apvector.h" struct Parts{ //Defines Structs int partNum; apstring descrip; int quanity; }; // Function prototypes: int Find (const apvector &inventory, int partNum); void Show (const apvector &inventory, int partNum); void Add (apvector &inventory, int partNum); void Remove (apvector &inventory, int partNum); void List (const apvector &inventory); //**************************************************************** //**************** main ******************* //**************************************************************** int main() { ifstream inFile("parts.dat"); apvector inventory(20); // Array of items (initially empty) char cmd; int i=0, partNum; inFile>>inventory[i].partNum; while (inFile) { inFile.ignore (200, '\n'); getline(inFile, inventory[i].descrip); inFile>>inventory[i].quanity; i++; inFile>>inventory[i].partNum; } inventory.resize(i); cout << "\n More Than One Of Each, Inc.\n"; cout << " Inventory Control System\n"; for(;;) { // Repeat (until break) // Show the menu and prompt: cout << "\n"; // Output a blank line cout << "\t (S)how inventory item\n"; // '\t' is tab cout << "\t (A)dd item\n"; cout << "\t (R)emove item\n"; cout << "\t (L)ist inventory\n"; cout << "\t (Q)uit\n"; cout << endl; cout << "Next command ==> "; // Accept command: cin >> cmd; // Read one char. cin.ignore(80, '\n'); // Skip remaining input (up to 80 // chars) to the end of the line. cmd = toupper(cmd); // Convert letter to upper case // to allow lower case input // for commands (for convenience). // Quit if 'Q' if (cmd == 'Q') break; // Quit processing commands cout << "\n\n****************************************\n"; // Process command: switch (cmd) { case 'S': // Show inventory item information cout << "Part number: "; cin >> partNum; Show(inventory, partNum); break; case 'R': // Removes invenotry item information cout<<"Part number: "; cin>>partNum; Remove (inventory, partNum); break; case 'A': // Adds inventory item information Add (inventory, partNum); break; case 'L': List (inventory); // lists all inventory items break; } inFile.close(); cout << "****************************************\n"; } return 0; } //**************************************************************** //**************** Functions ******************* //**************************************************************** int Find (const apvector &inventory, int partNum) // Finds the part number, partNum, in the inventory array. // Returns its index if found, -1 otherwise. { int i, nItems = inventory.length(); for (i = 0; i < nItems; i++) if (inventory[i].partNum == partNum) return i; return -1; } //**************************************************************** void Show (const apvector &inventory, int partNum) // Displays inventory information for the given part number. { int nItems, i=Find(inventory, partNum); if (i<0) cout<<"Sorry, This part is not in the inventory. It will be back ordered. "< &inventory, int partNum) // Adds the new inventory item with the specified part number, // partNum, to the inventory list. // Checks whether partNum is already in the list. { int nItems, quanity; char ans; cout<<"Would you like to add a part or a quantity?"<>ans; if((ans=='p') || (ans=='P')) { nItems = inventory.length(); inventory.resize(nItems+1); inventory[nItems].partNum = partNum; cout<<"Please enter the part description: "<>inventory[nItems].partNum; cout<<"Please enter the quantity you would like to add: "<>inventory[nItems].quanity; cout<>partNum; cout<<"Please enter the quantity you would like to add: "<>quanity; inventory[Find(inventory, partNum)].quanity+=quanity; cout << "added to the inventory list.\n"; } else { cout<<"Please enter P or Q. "< &inventory, int partNum) // Removes the item partNum from the inventory list, if it // is there. Displays an appropriate message if partNum is not // in the list. { int i, j, nItems, quanity; char ans; cout<<"Would you like to remove the item from the list? "<>ans; if (ans=='y' || ans=='Y') { i = Find(inventory, partNum); if (i < 0) cout << "not found.\n"; else { nItems = inventory.length(); for (j = i+1; j < nItems; j++) // Shift items inventory[j-1] = inventory[j]; // to fill the gap. inventory.resize(nItems - 1); cout << "removed from the inventory list.\n"; } } else if(ans=='n' || ans=='N') { cout<<"Please enter the quantity you would like to remove: "<>quanity; inventory[Find(inventory, partNum)].quanity-=quanity; if(inventory[Find(inventory, partNum)].quanity<0) cout<<"This order has been back ordered."< &inventory) // Displays the inventory list. { int nItems, j; nItems = inventory.length(); j=0; cout<<"Part Number Decsription Quanity"< l **************************************** Part Number Decsription Quanity 1 CPU 50 2 Memory Chips 150 3 Mother Boards 10 4 10 GB Hard Drives 10 5 20 GB Hard Drives 10 6 Sound Cards 5 7 40x CD-Rom Drives 5 8 12x DVD Drives 5 9 15 inch Monitor 2 10 17 inch Monitor 1 **************************************** (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit Next command ==> a **************************************** Would you like to add a part or a quantity? q Please enter the part number: 1 Please enter the quantity you would like to add: 10 added to the inventory list. **************************************** (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit Next command ==> a **************************************** Would you like to add a part or a quantity? q Please enter the part number: 2 Please enter the quantity you would like to add: 25 added to the inventory list. **************************************** (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit Next command ==> a **************************************** Would you like to add a part or a quantity? p Please enter the part description: 8x8x32 CDRW Please enter the part number: 11 Please enter the quantity you would like to add: 2 8x8x32 CDRW is now added to the list. **************************************** (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit Next command ==> a **************************************** Would you like to add a part or a quantity? p Please enter the part description: 40 GB Hard Drive Please enter the part number: 12 Please enter the quantity you would like to add: 2 40 GB Hard Drive is now added to the list. **************************************** (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit Next command ==> r **************************************** Part number: 11 Would you like to remove the item from the list? n Please enter the quantity you would like to remove: 5 removed to the inventory list. **************************************** (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit **************************************** Part number: 11 Would you like to remove the item from the list? n Please enter the quantity you would like to remove: 5 This order has been back ordered. **************************************** (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit **************************************** Part number: 12 Would you like to remove the item from the list? n Please enter the quantity you would like to remove: 5 This order has been back ordered. **************************************** (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit Next command ==> r **************************************** Part number: 4 Would you like to remove the item from the list? n Please enter the quantity you would like to remove: 5 removed to the inventory list. **************************************** (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit Next command ==> r **************************************** Part number: 9 Would you like to remove the item from the list? n Please enter the quantity you would like to remove: 2 removed to the inventory list. **************************************** (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit Next command ==> a **************************************** Would you like to add a part or a quantity? q Please enter the part number: 3 Please enter the quantity you would like to add: 8 added to the inventory list. **************************************** (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit Next command ==> a **************************************** Would you like to add a part or a quantity? q Please enter the part number: 4 Please enter the quantity you would like to add: 5 added to the inventory list. **************************************** (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit Next command ==> r **************************************** Would you like to add a part or a quantity? 6 Please enter P or Q. Would you like to add a part or a quantity? a Please enter P or Q. Would you like to add a part or a quantity? q Please enter the part number: 6 Please enter the quantity you would like to add: 10 added to the inventory list. **************************************** (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit Next command ==> a **************************************** Would you like to add a part or a quantity? q Please enter the part number: 10 Please enter the quantity you would like to add: 2 added to the inventory list. **************************************** (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit Next command ==> r **************************************** Part number: 25 Would you like to remove the item from the list? n Please enter the quantity you would like to remove: 10 removed to the inventory list. **************************************** (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit Next command ==> (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit Next command ==> r **************************************** Part number: 10 Would you like to remove the item from the list? n Please enter the quantity you would like to remove: 5 removed to the inventory list. **************************************** (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit Next command ==> r **************************************** Part number: 3 Would you like to remove the item from the list? n Please enter the quantity you would like to remove: 5 removed to the inventory list. **************************************** (S)how inventory item (A)dd item (R)emove item (L)ist inventory (Q)uit Next command ==> q Press any key to continue End Result: **************************************** Part Number Decsription Quanity 1 CPU 40 2 Memory Chips 125 3 Mother Boards 7 4 10 GB Hard Drives 10 5 20 GB Hard Drives 10 6 Sound Cards -5 7 40x CD-Rom Drives 5 8 12x DVD Drives 5 9 15 inch Monitor 4 10 17 inch Monitor 4 11 8x8x32 CD-RW 7 12 40 GB Hard Drive 7 25 Web Cam 10 **************************************** */