The program runs and has no errors, except for a memory leak. I thought I deleted all the dynamic memory blocks but I can't see where I'm missing the deletes. All cases where new and delete are used in my code are below. Also I have to use dyn arrays for this project, even though vectors would be infinitely easier.
The arrays are first created and dyn memory comes into play
void Zoo::increaseInventory(int type)
{
int newTigerSize=tigerArraySize*2;
int newPenguinSize=penguinArraySize*2;
int newTurtleSize=turtleArraySize*2;
if (type==1)
{
Tiger** newTigers = new Tiger* [newTigerSize]; //make new dyn array x2 the size
for (int count=0; count<(newTigerSize); count++) //set elements to null
{
newTigers[count]=NULL;
}
for (int count=0; count<tigerArraySize; count++) //copy old array into new array
{
newTigers[count]=tigers[count];
}
delete [] tigers; //delete old array
tigers=newTigers; //set member variable to new array
tigerArraySize*=2; //update array size
}
elseif (type==2)
{
Penguin** newPenguins = new Penguin* [newPenguinSize]; //make new dyn array x2 the size
for (int count=0; count<(newPenguinSize); count++) //set elements to null
{
newPenguins[count]=NULL;
}
for (int count=0; count<(penguinArraySize); count++) //copy old array into new array
{
newPenguins[count]=penguins[count];
}
delete [] penguins; //delete old array
penguins=newPenguins; //set member variable to new array
penguinArraySize*=2; //update array size
}
elseif (type==3)
{
Turtle** newTurtles = new Turtle* [newTurtleSize]; //make new dyn array x2 the size
for (int count=0; count<(newTurtleSize); count++) //set elements to null
{
newTurtles[count]=NULL;
}
for (int count=0; count<(turtleArraySize); count++) //copy old array into new array
{
newTurtles[count]=turtles[count];
}
delete [] turtles; //delete old array
turtles=newTurtles; //set member variable to new array
turtleArraySize*=2; //update array size
}
}