#include using namespace std; struct ArrayT { int * data{nullptr}; size_t capacity{0}; size_t size{0}; }; void MakeArray(ArrayT & ary, size_t newCapacity); void TellAboutArray(const ArrayT & ary); //void GrowArray(ArrayT & ary, size_t newCapacity); void PrintArray(ArrayT & array); void CleanUpArray(ArrayT & array); int main() { ArrayT ary; TellAboutArray(ary); MakeArray(ary,10); TellAboutArray(ary); ary.data[ary.size++] = 10; TellAboutArray(ary); PrintArray(ary); CleanUpArray(ary); return 0; } void MakeArray(ArrayT & ary, size_t newCapacity){ if (ary.data != nullptr) { cout << "Error, can not make a new array, it already exists" << endl; } else { ary.data = new int[newCapacity]; ary.size = 0; ary.capacity = newCapacity; } } void TellAboutArray(const ArrayT & ary){ if(ary.data == nullptr) { cout << "This array has not been allocated" << endl; } else { cout << "This array holds " << ary.capacity << " elements." << endl; cout << "This array has " << ary.size << " elements." << endl; } cout << endl; } void PrintArray(ArrayT & array){ if(array.data != nullptr) { for(size_t i =0; i < array.size; ++i) { cout << "array[" << i <<"] = " << array.data[i] << endl; } } else { cout << "Error, the array is not allocated " << endl; } cout << endl; } void CleanUpArray(ArrayT & array){ if(array.data != nullptr) { delete[] array.data; } }