/********************************************************************** Eclipse.cpp Programmed by: Mark M. Cruz IB/AP Computer Science Eclipse.cpp keeps a running inventory of parts ***********************************************************************/ #include #include #include const int MAX_ITEMS = 5; typedef int InventoryArray[MAX_ITEMS]; void DisplayWelcomeMessage(); void DisplayClosingMessage(); void OutputInventory(const InventoryArray items); // const used to protect the array from being changed void InputInventory(InventoryArray items); void ProcessChoices(); void OutputOneInventoryAmount(int amount, int itemCode); void ChangeOneInventoryAmount(InventoryArray items, int itemCode); char GetItemCode(); void DeductInventory(InventoryArray items, int itemCode); void AddInventory(InventoryArray items, int itemCode); char GetUsersChoice(); void main() { DisplayWelcomeMessage(); ProcessChoices(); DisplayClosingMessage(); } void DisplayWelcomeMessage() { cout << "\n"; cout << "*****************************************************************************\n"; cout << " W E L C O M E T O\n\n"; cout << " T H E\n\n"; cout << " E C L I P S E I N V E N T O R Y P R O G R A M\n"; cout << "*****************************************************************************\n"; } void DisplayClosingMessage() { cout << "\n"; cout << "*****************************************************************************\n"; cout << " T H A N K S F O R \n cout << " S T O P P I N G B Y ! ! ! cout << " H A V E A N I C E D A Y. :) cout << "*****************************************************************************\n"; } void ProcessChoices() { InventoryArray itemInventory; char choice; int itemCode; InputInventory(itemInventory); // Create the initial inventory bool done = false; choice = GetUsersChoice(); while (!done) { switch (choice) { case 'L': // List Inventory case 'l': OutputInventory(itemInventory); break; case 'G': // Single product listed case 'g': itemCode = GetItemCode(); while ((itemCode < MAX_ITEMS) && (itemCode >= 0)) // check to make sure code is valid - user is told to enter neg # to stop { OutputOneInventoryAmount(itemInventory[itemCode], itemCode); itemCode = GetItemCode(); cout << "\n\n\n"; } break; case 'C': case 'c': itemCode = GetItemCode(); while ((itemCode < MAX_ITEMS) && (itemCode >= 0)) // check to make sure code is valid - user is told to enter neg # to stop { ChangeOneInventoryAmount(itemInventory, itemCode); itemCode = GetItemCode(); cout << "\n\n\n"; } break; case 'A': // Add to inventory case 'a': itemCode = GetItemCode(); while ((itemCode < MAX_ITEMS) && (itemCode >= 0)) // check to make sure code is valid - user is told to enter neg # to stop { AddInventory(itemInventory, itemCode); itemCode = GetItemCode(); cout << "\n\n\n"; } break; case 'D': // Deduct from inventory case 'd': itemCode = GetItemCode(); while ((itemCode < MAX_ITEMS) && (itemCode >= 0)) // check to make sure code is valid - user is told to enter neg # to stop { DeductInventory(itemInventory, itemCode); itemCode = GetItemCode(); cout << "\n\n\n"; } break; case 'E': case 'e': cout << "Do you want to really want top quit (Y) or (N)\n"; char answ; cin >> answ; if ((answ =='Y') || (answ == 'y')) { done = true; } break; default: cout << "Invalid choice. Please Select again.\n\n"; } // end switch if (!done) { choice = GetUsersChoice(); } } } char GetUsersChoice() { char choice; cout << "\n\n\n\n"; cout << "Please enter the letter which corresponds to what you want to do\n" " to List all the inventory\n" " to Get the inventory of one item\n" " to deduct from the inventory of an item\n" " to add to the inventory of an item\n" " to change the inventory of an item\n" " to Exit\n"; cin >> choice; return choice; } char GetItemCode() { int code; cout << "Please enter the code for the item you wish to work with\n"; cout << "Enter a negative number to indicate you are finished\n"; cin >> code; while (code > MAX_ITEMS -1) // check for code that is too high { cout << "Invalid item code. Please enter a valid code.\n"; cin >> code; } // cin.ignore(1); return code; } void OutputOneInventoryAmount(int amount, int itemCode) { cout << endl << endl << "The inventory amount for item " << itemCode << " is: " << amount << endl << endl; } void OutputInventory(const InventoryArray items) { cout << "\n\n\n\n\n"; for (int itemCode = 0; itemCode < MAX_ITEMS; itemCode++) { cout << "The inventory amount for item " << itemCode << " is: " << items[itemCode] << endl; } cout << "\n\n\n\n\n\n"; } void InputInventory(InventoryArray items) { int itemAmount; for (int itemCode = 0; itemCode < MAX_ITEMS; itemCode++) { cout << "Please enter the inventory count for item " << itemCode << ": "; cin >> itemAmount; items[itemCode] = itemAmount; } } void ChangeOneInventoryAmount(InventoryArray items, int itemCode) { int amount; cout << "Please enter the new amount in the inventory\n"; cin >> amount; items[itemCode] = amount; } void DeductInventory(InventoryArray items, int itemCode) { int amount; cout << "Please enter the amount sold of item\n"; cin >> amount; items[itemCode] -= amount; } void AddInventory(InventoryArray items, int itemCode) { int amount; cout << "Please enter the amount to add of item\n"; cin >> amount; items[itemCode] += amount; }