/************************************************************************ Program Name: Eclipse.cpp Programmed by: Mark Cruz School: Princess Anne High School Program Language used: C++ Computer Used: Compaq Deskpro and Sony Vaio Purpose: To create and maintain a running parts inventory for an automobile. Date: March 12, 2003 ************************************************************************/ #include #include #include // Declares toupper(ch) #include #include "apvector.h" #include "apstring.h" struct parts // This defines the data type for the array { int partNumber; int quantity; apstring descrip; }; int Find (const apvector &inventory, int partNumber); //User doesn't see, makes sure partnumber exists void Show (const apvector &inventory, int partNumber); //Displays information on current part void Add (apvector &inventory, int partNumber, int quant, apstring description); //adds part to inventory void Remove (apvector &inventory, int partNumber, int quantity1); //Removes part from inventory void List (const apvector &inventory); //Displays the current inventory int quantity1; int main() { apvector inventory(1); // Array of items apstring filename; char choice, answer; int partNumber, quant, i=0, n=0, h; apstring description; ofstream outfile; ifstream infile, infile1, infile2, infile3; infile.open ("inventory.txt"); infile >> inventory[i].partNumber; while(infile) { infile>>inventory[i].quantity>>inventory[i].descrip; inventory.resize(inventory.length()+1); i++; infile >> inventory[i].partNumber; } inventory.resize(inventory.length()-1); infile.close(); 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"; for(;;) { // Repeat (until break) // Show the menu and prompt: cout << "\n" // Output a blank line "Hello! Please enter the letter in parenthesis to.......\n" "\t (E)xecute the command to SHOW the information for a SINGLE ITEM\n" // '\t' is tab "\t (C)redits\n" "\t (L)ist the current inventory\n" "\t (I)nitiate the procedure to ADD AN ITEM from the inventory\n" "\t (P)urge a quantity of an item from your inventory\n" "\t (S)ave and exit the program to doing better and greater things\n" "\t (E)xecute the command to SHOW the information for a SINGLE ITEM\n\n" "Please Enter Your Next Choice : "; cin >> choice; // Read one char. cin.ignore(80, '\n'); // Skip remaining input (up to 80 // chars) to the end of the line. choice = toupper(choice); // Convert letter to upper case // to allow lower case input // for commands (for convenience). if (choice == 'S') { cout << "Hey! Do you wanna save before exiting????\n "; cout <<" Please Enter: (Y) for Yes or (N) for No \n"; cin >> answer; answer=toupper(answer); //again we change the input to an uppercase for simplicity if (answer == 'Y') { outfile.open("inventory.txt"); for (h=0; h< inventory.length(); h++) { outfile << inventory[h].partNumber << " "<< inventory[h].quantity<< " "<> partNumber; Show(inventory, partNumber); break; case 'C': // Show the Credits cout << "\n\n"; cout << "*****************************************************************************\n"; cout << "* Eclipse Inventory Program *\n"; cout << "* Programmed by *\n"; cout << "* Mark Cruz for International Baccalaureate, 2003 *\n"; cout << "*****************************************************************************\n"; break; case 'L': // List inventory List(inventory); break; case 'I': // Add inventory item cout << "Part Number: "; cin >> partNumber; cout << "Description: " ; cin >> description; cout << "Quantity: "; cin >> quant; Add(inventory, partNumber, quant, description); break; case 'P': // Remove inventory item cout << "Part Number: "; cin >> partNumber; cout << "How many items do you wish to remove? " ; cin >> quantity1; Remove(inventory, partNumber, quantity1); break; } cout << "****************************************\n"; } return 0; } int Find (const apvector &inventory, int partNumber) // Finds the part number, partNumber, in the inventory array. // Returns its index if found, -1 otherwise. { int i, nItems; nItems = inventory.length(); for (i = 0; i < nItems; i++) if (inventory[i].partNumber == partNumber) return i; return -1; } //**************************************************************** void Show (const apvector &inventory, int partNumber) // Displays inventory information for the given part number. { int i; i = Find(inventory, partNumber); if (i <= - 1) cout <<"Sorry. That part could not be found. Please try again.\n"; else { cout << "Part Number: " << partNumber << endl; cout << "Quantity: " << inventory[i].quantity << endl; cout << "Description: " << inventory[i].descrip << endl; } } //**************************************************************** void Add (apvector &inventory, int partNumber, int quant, apstring description) // Adds the new inventory item with the specified part number, // partNumber, to the inventory list. // Checks whether partNumber is already in the list. { int i, nItems; apstring tDescrip; i = Find(inventory, partNumber); if (i>=0) { cout << "That Item is already in the inventory. The quantity will be added to existing amount. \n"; inventory[i].quantity=inventory[i].quantity+quant; cout << "Your new item total is: "<< inventory[i].quantity << ". " << endl; cout << endl; } else { nItems = inventory.length(); inventory.resize(nItems+1); inventory[nItems].partNumber = partNumber; inventory[nItems].quantity = quant; inventory[nItems].descrip = description; cout << "Your Item(s) have been added to the inventory!\n"; } } //**************************************************************** void Remove (apvector &inventory, int partNumber, int quantity1) { int i =Find(inventory, partNumber); if (i < 0) cout << "Sorry! Part not found!!\n"; else if (inventory[i].quantity &inventory) // Displays the inventory list. { int i; cout << "Items in the inventory: "<