I have a very similar issue. I am also doing and assignment and needed a function grow. This was to increase the size of the object array Savings by s, if it was not NULL, or make its size s if it was null. In both the case it was to check if the memory allocation was successful. This is where i get stuck. Any suggestions on how to get the size and compare it with the old one, other than ofcourse creating a for loop! LOL!
//'s' is the variable for the size.
int Bank::grow(int s = 10){
int sizeOld = size; //used to save the size for future comparison
if(savings != NULL){
//create a new account object array
Account *newSavingsArray = new Account[arraySize + s]
//copy all data from old array to new
for ( int i = 0; i < arraySize; i++ ){
newSavingsArray[i] = savings[i];
}
delete savings;
arraySize = arraySize + s;
savings = newSavingsArray;
}
else if (savings == NULL){
//recreate the savings object with size 's'
Account *savings = new Account[s]
arraySize = s;
}
return arraySize;
}