// CIS 235 Lecture 7 // Driver Program Inventory of Containers // Client Function to input one container into an inventory #include #include #include "container.h" #include "inventory.h" using namespace::std; bool keyboardInput(inventory &); // user written function void main(void) { inventory inv; int howMany, i; cout << "Enter the number of items in the inventory "; cin >> howMany; for( i = 1 ; i <= howMany ; i++ ) { if (keyboardInput(inv) ) cout << "ADDED\n"; else cout << "No More Room - NOT Added\n"; } inv.printAll(cout); char desc[30]; cout << "Try the search" << endl; cout << "Enter a one word description to search for " << "enter done when finished "; while ( cin >> desc, strcmp(desc,"done") != 0 ) { i = inv.search(desc); if ( i == -1 ) cout << "Not Found" << endl; else { cout << "Found in cell " << i << endl; inv.printOne(cout,i); } } // end while cout << "Print all items\n"; inv.printAll(cout); // test inventory copy constructor inventory dup(inv); cout << "\nPrint all of copy\n"; dup.printAll(cout); return; } bool keyboardInput( inventory & in) { if( in.isFull() ) return false; int size, used; char desc[200]; cout << "Enter size, used, and description(no spaces):" << endl; cin >> size >> used >> desc; // no need for a work container variable // call a container constructor as the parameter in.placeInto(container(size,used,desc)); return true; } /* My output Enter the number of items in the inventory 3 Enter size, used, and description(no spaces): 2 1 firstArray ADDED Enter size, used, and description(no spaces): 5 1 secondArray ADDED Enter size, used, and description(no spaces): 10 10 thirdArray ADDED List of all filled cells in inventory Capacity 2 Used 1 Description firstArray Capacity 5 Used 1 Description secondArray Capacity 10 Used 10 Description thirdArray Try the search Enter a one word description to search for enter done when finished Array Not Found one Not Found a Not Found k Not Found 5 Not Found third Not Found firstArray Found in cell 0 Capacity 2 Used 1 Description firstArray done Print all items List of all filled cells in inventory Capacity 2 Used 1 Description firstArray Capacity 5 Used 1 Description secondArray Capacity 10 Used 10 Description thirdArray Print all of copy List of all filled cells in inventory Capacity 2 Used 1 Description firstArray Capacity 5 Used 1 Description secondArray Capacity 10 Used 10 Description thirdArray Press any key to continue . . .