I have a class called WeigglhBridge which has one of this method named removeTruck(int).
The class I mentioned above has an account object named Truck record[] which is an array of objects consisting of various trucks.
Now, getting to the main question, the removeTruck(int) method must receive an index as input parameter and remove an existing truck from the list, which is basically "record []".
It involves no pointers. It's just composition.
Please help me, I'm preparing for my exam.
I'm going to take a stab at this... Since arrays are static, they can not change their size during run time. If you declare your array with 100 elements, it's going to stay 100 elements.
Therefor I don't think you can "Delete" an object in this manner, rather you set the value to zero.
That is a simple record[index] = 0;
If you want to physically delete the element you should be using vectors, or lists.
Vectors can be resized.
Lists you manage by changing 2 pointers.
I hope I understood your question properly, and I hope even more I got it right for you...
In order to "remove" an element of an array, you need to move all elements at higher indexes down and decrement the variable you're using to keep track of the number of elements in the array.
That's not a hard concept. For example, if the truck you want to remove is number 63.
element 63 now == 64
element 64 now == 65
element 65 now == 66
element 66 now == 67
element 67 now == 68 and your last element will == itself. It's not deleted as much as over written. You just have to treat your array as if it had fewer elements. You could insert an object by reversing the process..
@Cire - Genius in it's simplicity. I wouldn't have thought of that in a hundred years.