NumberBag That Doubles Its Buffer
mediumQuestion 701Write a class NumberBag that grows its own storage — without std::vector.
Private members: int* data;, int count; (values stored), int capacity; (what the buffer can hold).
Public interface:
NumberBag(int initialCapacity);
~NumberBag();
void add(int value);
int get(int index) const;
int size() const; // count
int getCapacity() const; // capacityThe growth rule, exactly: if the buffer is full (count == capacity), add first allocates a new array of capacity * 2, copies the existing values into it, releases the OLD array, and keeps the new one. Then it stores the value and increases count. If not full, just store the value — no reallocation.
The driver reads initialCapacity n then n values, adds them all, and prints the size, the capacity, then the values on one line separated by single spaces. For the input:
2 5
4 8 15 16 23the exact output is what is shown in Expected Output.
Free the memory you allocate — this question checks for memory leaks.
Do NOT write a main function.
Expected output
size=5 capacity=8 4 8 15 16 23
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...