Who's car is this??? It Must Be.......

Mark Cruz
March 18, 2003
IB Class of 2003
TABLE OF CONTENTS

Table of Contents	2
Problem Statement/Discussion	3-4
Algorithm in PURE	5-10
Data Structure	11
Evidence of User Friendliness	12
Error Handling Facilities	12
Program Listing 	14-22
Testing Strategy/Plan	23
Sample Output	24-29		
User Documentation	30-31
Conclusion	32

Problem Statement

	The goal of this program, Eclipse.cpp, was originally to catalog and maintain a running parts inventory for a 1997 Mitsubishi Eclipse RS equipped with a manual transmission; however, during coding, the goal was expanded to a program that is capable of cataloging and updating a running lists of parts for virtually anything. The program will give the user several options. The user will be able to control an inventory list by adding and deleting parts from inventory. The program will also display descriptions, part numbers, and quantities available for the parts in the inventory. For longevity, the program will have the ability to save the current inventory information upon exit so that the inventory will be able to be maintained constantly. This information will be kept in an external file, which is accessed twice, once when the program opens to read the information and once when the program closes and saves the current inventory information. This program will use a struct to maintain and access the inventory efficiently. 

	When the program is run, the user will be presented with an initial menu which lists all the vital functions of the program. The menu presents the user with several possible courses of action. The first possible option will allow the user to show the information of an item. The next option will allow the user to add an item into the current inventory. The third option gives the user the option to Remove an item from the inventory, while the fourth option allows the user to change the quantity of an item currently in the inventory. The final option will allow the user to exit the program and save the changes that have been made to the current inventory list. 

	At the menu, if the user enters S for SHOW, the user will be able to search for a specific part by entering a part number at the specified prompt. When a correct part number is entered by the user, the program will display the part number, description, and quantity available in the current inventory. If the part number cannot be found in the current inventory list, the program will inform the user that the part could not be found. The user will then have the option to search for another part by part number or return to the intial menu. 

	At the menu, if the user enters the letter I, the user will be asked to enter the part number that he or she wishes to work with. Next, the program will check the inventory for the part number. If it is currently a part in the inventory, the program will ask the user for the new quantity of items. If the part number is not found, the program will automatically add the part to the current inventory under the new part number that was entered by the user. 

	At the menu, if the user chooses option P for PURGE, the user will be asked to enter a part number. As before, the program will check the inventory list for the part number. IF the part number is, the user will be asked if he or she really wants to remove the part from the inventory. If the part number entered by the user does not match one of the parts in the inventory list, the user will be told that the part does not exist and the program will reutnr to the the main menu. .

		If, from the main menu, the user enters L, the program will display an entire list of inventory for the user to review, which includes the part number, quantity, and description for each part. 

	If the users enters S for SAVE and quit, the program will ask the user if he or she really wants to exit and save the current inventory list changes. If the user does not want to save now, the user will be able to say no, and if the user chooses to exit, the program will make the appropriate changes to the inventory and save the resulting list in a file called "Inventory.txt". 

ALGORITHIM IN PURE

/************************************************************************
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
************************************************************************/

useslibrary  <IOSTREAM>
useslibrary  <IOMANIP>
useslibrary  <CTYPE> 
useslibrary  <FSTREAM >
useslibrary  <APVECTOR>
useslibrary  <APSTRING> 

newtype PARTS 	record
	integer PARTNUMBER
	integer QUANTITY
	string DISCRIP
			endrecord

declare integer QUANTITY1

main ECLIPSE
	declare INVENTORY is PARTS array [0...0]
	declare FILENAME string
	declare CHOICE string
	declare ANSWER string
	declare PARTNUMBER integer
	declare QUANT integer
	declare I integer
	declare N integer
	declare H integer
	declare FILE string file
	I <-- 0
	N <--0
	declare DESCRIPTION
	open(FILE)

	input(FILE)  INVENTORY[I].PARTNUMBER;

	while not eof(FILE) do
		input(FILE)  INVENTORY[I].QUANITY , INVENTORY[I].DESCRIP
		INVENTORY.resize(length(INVENTORY)+1);
		I=I+1
		input(FILE)  INVENTORY[I].PARTNUMBER;
	endwhile
		
	INVENTORY.resize(length(INVENTORY)-1);

	

output "                          W E L C O M E   T O";
output  "                                  T H E";
output  "               E C L I P S E   I N V E N T O R Y   P R O G R A M";

    repeat
             output "Hello! Please enter the letter in parenthesis to......."
	output  "(E)xecute the command to SHOW the information for a SINGLE ITEM
	output  "(C)redits"
	output  "(L)ist the current INVENTORY"
	output  "(I)nitiate the procedure to ADD AN ITEM from the INVENTORY"
	output  "(P)urge a QUANTITY of an item from your INVENTORY"
        	output  "(S)ave and exit the program to doing better and greater things"
	output  "(E)xecute the command to SHOW the information for a SINGLE ITEM"
        	output  "Please Enter Your Next Choice : "
	input CHOICE
	
           if (CHOICEchoice = 'S') then
		output "Hey! Do you wanna save before exiting???? "
		output " Please Enter: (Y) for Yes or (N) for No"
		input ANSWER
		if (ANWSER = 'Y') than
			for H<--0 upto length(INVENTORY) do
				outfile INVENTORY[H].PARTNUMBER, INVENTORY[H].QUANTITY, INVENTORY[H].DESCRIP
				close(FILE)
				return 0
			endfor
		elsif (ANSWER = 'N') then
			return 0
		endif 

	if (CHOICE = E) then
	            output  "Part Number: "
          	 	input PARTNUMBER
          		SHOW(INVENTORY, PARTNUMBER)
           elsif (CHOICE = C) then
		output "**********************************************"
		output  "*                         Eclipse INVENTORY Program;
		output  "*                               Programmed”
		output  "*               Mark Cruz for International Baccalaureate, 2003”
		output "**********************************************”
	elsif (CHOICE = L) then
	            LIST(INVENTORY);
            elsif (CHOICE = T) then
		output "Part Number: "
          		input PARTNUMBER
		output “description: " 
		input DESCRIPTION;
		output  “QUANTITY: "
		input  QUANT;
           		ADD(INVENTORY, PARTNUMBER, QUANT, DESCRIPTION)
	elsif (CHOICE = P) then
	            output  "Part Number: "
	            input PARTNUMBER;
		output  "How many itemsdo you wish to remove? " 
		input  QUANTITY1
		REMOVE(INVENTORY, PARTNUMBER, QUANTITY1)
	endif
        
until (CHOICE = Q)
endmain ECLIPSE 

function FIND (ref INVENTORY is PARTS array [0...length(INVENTORY)],
		 val PARTNUMBER integer)
result integer

/* Finds the part number, PARTNUMBER, in the INVENTORY array.*/
/* Returns its index if found, -1 otherwise.*/
	declare I integer
	declare NITEMS integer
	NITEMS <--length(INVENTORY)

	for i<--0 upto NITEMS do
	        if (INVENTORY[Ii].PARTNUMBER = PARTNUMBER) then
	        return Ii;
	endfor
    return -1;
endfunction FIND

procedure SHOW (INVENTORY is PARTS array [0...length(INVENTORY)]
		, val PARTNUMBER integer)
	declare I integer
	I <-- FINDind(INVENTORY, PARTNUMBER);
	if (I <= -1) than
		output "Sorry. That part could not be found. Please try again."
	else
		output "Part Number: ",  PARTNUMBER
		output "QUANTITY: ",  INVENTORY[I].QUANTITY 
		output "DESCRIPTION: ",  INVENTORY[I].DESCRIP
	endif
endprocedure SHOW

procedure ADD (INVENTORY is PARTS array [0...0], val PARTNUMBER integer, val QUANT integer, DESCRIPTION string)

/* Adds the new INVENTORY item with the specified part number, */
/*   PARTNUMBER, to the INVENTORY list. */
/*   Checks whether PARTNUMBER is already in the list. */
	declare I integer
	declare NITEMS integer
	declare TDESCRIP string

	I = FIND(INVENTORY, PARTNUMBER);
	if (I>=0) than
		output "That Item is already in the INVENTORY. The QUANTITY will be added to existing amount.”
		INVENTORY[I].QUANTITY=INVENTORY[I].QUANTITY+QUANT
		output "Your new item total is: “,INVENTORY[I].QUANTITY
	else
		NITEMS =length(INVENTORY)
		INVENTORY.resize(NITMESnItems+1)
		INVENTORY[NITEMS].PARTNUMBER = PARTNUMBER
		INVENTORY[NITEMS].QUANTITY = QUANTt
		INVENTORY[NITEMS].DESCRIP = DESCRIPTION
		output "Your Item(s) have been added to the INVENTORY!”
    	endif
endprocedure ADD

procedure REMOVE (INVENTORY is PARTS array [0...length(INVENTORY)], val PARTNUMBER integer, val QUANTITY1 integer)

	declare I  integer
	I = FIND(INVENTORY, PARTNUMBER)

  	if (I < 0) then
       		 output  "Sorry! Part not found!!"
   	elsif (INVENTORY[Ii].QUANTITY<QUANTITY1) then
		output "Sorry, you don't have that many items in stock!"
		output "Please order more!!"
	else 
		INVENTORY[Ii].QUANTITY=INVENTORY[Ii].QUANTITY-QUANTITY1
    	    	output  QUANTITY1 ," item(s) removed from the INVENTORY." 	endif
endprocedure REMOVER

procedure LIST (INVENTORY is PARTS array [0...length(INVENTORY)])

/* Displays the INVENTORY list. */
   declare I integer
   output  "Items in the INVENTORY: "
   output  "Part Number  QUANTITY  DESCRIPTION" 

   for I<-- 0 upto length(INVENTORY) do
	   output   INVENTORY[I].PARTNUMBER,  INVENTORY[I].QUANTITY,  			INVENTORY[I].DESCRIP
   endfor
   if (i=0) then
	   output  "Sorry! No parts were found."
  endif
endprocedure LIST

DATA STRUCTURE
0	

1	

2	

	Int Part Number

Apstring Description

Int Quantity

A struct was chosen due to the fact that it seemed to be the most viable option at the time of program coding. It speeds up search time because all information is kept in one area. Structs are then placed in arrays, which have information for each part, allowing for easier data manipulation and searching. 

Error Handling

Error handling is implemented in some portions of code. For example, a negative integer would most likely cause the program to crash, however, this is handled in the following segment of code.

    int i;
	i = Find(inventory, partNumber);
	if (i <= - 1)
cout <<"Sorry. That part could not be found. Please try again.\n";
This assures that the user does not input a negative number. 

Further evidence of a similar type of error handling is also evident in this segment of code in the Remove Function.

int i =Find(inventory, partNumber);

    if (i < 0)
        cout << "Sorry! Part not found!!\n";

Again this prevents the input of a negative number. 

User Friendliness

	The program is user friendly, with easy to navigate menus and instructions, such as the one below. 

*****************************************************************************
                          W E L C O M E   T O

                                  T H E

               E C L I P S E   I N V E N T O R Y   P R O G R A M
*****************************************************************************

Hello! Please enter the letter in parenthesis to.......
         (E)xecute the command to SHOW the information for a SINGLE ITEM
         (C)redits
         (L)ist the current inventory
         (I)nitiate the procedure to ADD AN ITEM from the inventory
         (P)urge a quantity of an item from your inventory
         (S)ave and exit the program and do better and greater things
         (E)xecute the command to SHOW the information for a SINGLE ITEM

Please Enter Your Next Choice :

Users can enter letters which correspond to program functions, allowing for easier access. 

PROGRAM LISTING

/************************************************************************
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 <iostream.h>
#include <iomanip.h>
#include <ctype.h>                 // Declares toupper(ch)
#include <fstream.h>
#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<parts> &inventory, int partNumber); //User doesn't see, makes sure partnumber exists
void Show (const apvector<parts> &inventory, int partNumber); //Displays information on current part
void Add (apvector<parts> &inventory, int partNumber, int quant, apstring description); //adds part to inventory
void Remove (apvector<parts> &inventory, int partNumber, int quantity1); //Removes part from inventory
void List (const apvector<parts> &inventory); //Displays the current inventory
int quantity1;

int main()

{
    apvector<parts> 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 and do 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<< " "<<inventory[h].descrip <<endl;
				}

				outfile.close();
				return 0;
			}

			else if (answer == 'N')
			{
				return 0;
			}
		}

        cout << "\n\n****************************************\n\n";

        

        switch (choice)
		{

            case 'E':           // Show the info for one part

            cout << "Part Number: ";
            cin >> 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<parts> &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<parts> &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<parts> &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<parts> &inventory, int partNumber, int quantity1)

{
    int i =Find(inventory, partNumber);

    if (i < 0)
        cout << "Sorry! Part not found!!\n";

    else if (inventory[i].quantity<quantity1)
	{
		cout<< "Sorry, you don't have that many items in stock!\n";
		cout<< "Please order more!!\n";
		
	}
	else 
	{	
		inventory[i].quantity=inventory[i].quantity-quantity1;		
        cout << quantity1<< " item(s) removed from the inventory.\n";
    }
}

//****************************************************************

void List (const apvector<parts> &inventory)

// Displays the inventory list.

{
   int i;
   cout << "Items in the inventory: "<<endl;
   cout << "Part Number" << setw(10) << "Quantity" << setw(17) << "Description" << endl;

   for (i=0; i < inventory.length(); i++)
   {
	   cout << setw(5) << inventory[i].partNumber << setw(13) << inventory[i].quantity << setw(17) << inventory[i].descrip << endl;
   }
   if (i==0) // if there is nothing in the list
	   cout << "Sorry! No parts were found.";
   cout << endl;
}

User Manual 
Eclipse.exe User Manual

To run the program, simply double click the eclipse.exe file that is included. You will be presented with several options, arranged in a menu that looks like this:

*****************************************************************************
                          W E L C O M E   T O

                                  T H E

               E C L I P S E   I N V E N T O R Y   P R O G R A M
*****************************************************************************

Hello! Please enter the letter in parenthesis to.......
         (E)xecute the command to SHOW the information for a SINGLE ITEM
         (C)redits
         (L)ist the current inventory
         (I)nitiate the procedure to ADD AN ITEM from the inventory
         (P)urge a quantity of an item from your inventory
         (S)ave and exit the program and do better and greater things
         (E)xecute the command to SHOW the information for a SINGLE ITEM

Please Enter Your Next Choice :

At this screen, you will be prompted to enter a specific letter that corresponds with the action you wish to take. For example, you would enter an "S" if you wanted to save and exit the program.

The Show Option:

	This option is accessed by entering the letter ‘E’ at the menu screen. This option allows you to enter the part number for the part you wish to reference. Once you enter a correct part number, the program will give you the information for the part that is currently in the inventory list.

The Add Option:

	This option is accessed by entering the letter ‘I’ at the menu screen. This option will allow you to add a new part to the inventory or change the quantity of an existing part already in the inventory.

The Remove option:

	This option is accessed by entering the letter ‘P’ at the menu screen. This option allows you to remove items from your current inventory. It will not allow you to remove more parts than are currently in the inventory, and if presented with such a situation, will suggest that you order more items.

The List Option:

	This option is accessed by entering the letter ‘L’ at the menu screen. If this option is selected,the program will display a list of all items currently in teh inventory list. 

The Exit option
	This option is accessed by entering the letter ‘S’ at the menu screen. If this option is selected, you will be asked to confirm your exit as well as whether or not you wish to save. If you confirm your exit, the program will close. If you choose not to save, the external file, "Inventory.txt" will not be modified and none of your changes to the inventory will be saved.

The Credits option
	This option is accessed by entering the letter ‘C’ at the menu screen. This displays a little information about the program and its programmer. 

Known Bugs
Negative numbers will most likely cause an error in the program and thus should not be used. Also, the user must be careful to enter the correct data types at prompts. At the menu screen, only numeric data types should be entered. When asked for part number, the user must enter a numeric value or the program may crash. If the user attempts to enter data with spaces in the part description, the program will crash as well. It is recommended that the user use underscores instead of spaces. For example, entering “High Flow Exhaust” under part description would cause the program to crash, however, “High_flow_Exhaust” would not.  

The Conclusion

In the daunting process of programming this inventory program (redundancy anyone?), I learned several valuable lessons about C++, and about life in general. The first thing is that programming even the simplest programs is a HARD and TIME-CONSUMING process that SHOULD NOT be done in the course of several days, but rather in the course of several months. This dossier gave me a newfound appreciation for the Gigabytes of programs on my computer that run flawlessly.  

	Hours of coding and debugging have created a program that runs and does what it claims to do in the problem statement. The user can maintain a running list of inventory for virtually anything.

However, the programming does have several shortcomings. User input is limited in several manners. For Example, the user must enter underscores instead of spaces when entering descriptions for parts. Furthermore, a backorder option is not implemented. Also, in certain areas, the input of a character instead of an int will cause an infinite loop. In the future, I would like to fix such errors which would prevent the program from running as smoothly as possible.