A popular alternative to storing
railroad_car
objects in either ordinary arrays or lists is to store them in
self-expanding arrays. A self-expanding array is an array that gets
larger as more and more elements are added to it.
You can implement a self-expanding array as follows:
self_expanding_array
class that contains a member variable
assigned to an internal array of objects.
The following definition of the Integer_array
class embodies the
first two steps toward the creation of a self-expanding array of integers:
#include// Define global integer array: class Integer_array { public: // Constructor: Integer_array ( ) { hidden_array = new int[100]; } // Reader: int read_element (int n) { return hidden_array[n]; } // Writer: void write_element (int n, int i) { hidden_array[n] = i; } private: int* hidden_array; };
Modify the definition so as to complete the development.