#include using namespace std; const size_t MAX_SIZE{5000}; size_t GetSize(); void PrintArray( const int ary[], size_t size) ; void FillArray( int * ary, size_t size) ; int * MakeArray(size_t & size); int main() { size_t size; int * data{nullptr}; srand(time(nullptr)); size = GetSize(); data = MakeArray(size); FillArray(data, size); cout << "The array is: " << endl; PrintArray(data, size); if (data != nullptr) { delete[] data; } return 0; } int * MakeArray(size_t & size) { int * data{nullptr}; data = new int[size]; if (data == nullptr) { cout << "Error, failed to allocate the array " << endl; size = 0; } return data; } // YUCK, DON'T DO THIS!!! void FillArray( int * ary, size_t size) { for(size_t i =0; i < size; ++i) { *(ary+i) = rand() % MAX_SIZE; } } void PrintArray( const int ary[], size_t size) { for(size_t i=0; i < size; ++i) { cout << "\t" << i << "\t" << ary[i] << endl;; } } size_t GetSize() { size_t size; cout << "Enter the size of the array 1-1000 : "; cin >> size; cout << endl; if (size > 1000) { cout << " Sorry 1000 is the limit" << endl; } if (size == 0) { cout << " Sorry, it must be at least 1" << endl; size = 1; } return size; }