Say I have a history array of 10 indexes; when I fill the array with values up to the last index {0,1,2,3,4,5,6,7,8,9} and I "keep" updating the array for the last index {9} and replace it with a new value {10} while shifting the whole array into the same named array; but with the new value in the last index {1,2,3,4,5,6,7,8,9,10}.
I'm able to capture my operations history; but I'm unable to think of a way to keep updating the array whenever I exceed it's history length to keep only the last 10 operations. I understand how to assign the value to the last index; but I'm unable to create an operation to shift the initial indexes.
Any tips?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
double Account::operator+=(double value){
//overload +=
if ((value < 0) && abs(value)>balance){
throw balance;
}
balance = balance + value;
history[index] = balance;
index++ ;
//(index==10){
// index = 0;
// }
return balance;
}
|
This is part of the way there; but this overwrites from the first index, and doesn't shift the other indexies.