//Main Class
int main()
{
int count = 1; // Set up a counter for the dynamic array
int checkCount = 1; // checkCount is used to determine if the class arrays need to be swaped and a new element added
int currentCount = 0; // Set up a variable to keep track of which element of the array you are in
bool open = true; // Control for the main while loop
inventory *inv; // pointer to the class (used to create dynamic class array
inventory *temp; // temporary pointer that will be used when another element needs to be "added"
inv = new inventory[1]; // create memory for the class array
while (open)
{
system("cls"); // Clear the screen
// This is where the swapping takes place to add a new element
if (checkCount < count)
{
temp = new inventory[checkCount]; // create memory for the temp class array
for (int i=0;i<checkCount;i++) // swap from inv into temp
{
temp[i].invName = inv[i].invName;
temp[i].invAmount = inv[i].invAmount;
}
delete [] inv; // Free up the memory from inventory
inv = new inventory[count]; // Create inv array with the extra element
for (i=0;i<checkCount;i++) // swap from temp back to inv
{
inv[i].invName = temp[i].invName;
inv[i].invAmount = temp[i].invAmount;
}
delete [] temp; // Free the memory from temp
checkCount = count;
currentCount = count - 1;
}
// DISPLAY CURRENT INVENTORY //
cout << "CURRENT INVENTORY" << endl;
cout << "---------------------" << endl;
for (int i=0;i<count;i++)
{
inv[i].displayInv();
}
cout << "---------------------" << endl << endl;
// END DISPLAY CURRENT INVENTORY
// CREATE MENU FOR USER TO INPUT DATA //
int menuSelection = 0;
cout << "--------------------------" << endl;
cout << "1. Add inventory item " << endl;
cout << "2. Exit " << endl;
cout << "--------------------------" << endl;
cout << "Select an option: ";
cin >> menuSelection;
switch (menuSelection)
{
case 1:
inv[currentCount].addInventory();
count++;
break;
case 2:
open = false;
break;
default:
cout << "Please Select either 1 or 2 " << endl;
break;
}
}
system("pause");
return 0;
}