//Maxwell Brewer                 CS1A                     Chapter 9, p. 539, #11
//
/*******************************************************************************
 * ARRAY EXPANDER
 * _____________________________________________________________________________
 * This program will dynamically allocate an array of a specified size.
 * _____________________________________________________________________________
 * INPUT
 *   No direct input from the user
 * 
 * OUTPUT
 *   Prints the original and expanded arrays,
 *   showing the original values followed by zero-initialized elements.
 *
 ******************************************************************************/

#include <iostream>
using namespace std;

int* expandArray(int *arr, int SIZE) {
    // Dynamically allocate an array twice the size
    int *expPtr = new int[2 * SIZE];

    // Initialize elements of new array
    for (int i = 0; i < 2 * SIZE; i++) {
        if (i < SIZE) {
        	
            // Copy elements of the original array
            *(expPtr + i) = *(arr + i);
        } else {
        	
            // Initialize additional elements to 0
            *(expPtr + i) = 0;
        }
    }

    return expPtr;
}

int main() {
    int SIZE = 5;
    int *arr = new int[SIZE]{1, 2, 3, 4, 5};

    // Print original array
    cout << "Original array: ";
    for (int i = 0; i < SIZE; i++) {
        cout << arr[i] << " ";
    }
    cout << endl;

    // Expand the array
    int *expandedArr = expandArray(arr, SIZE);

    // Print expanded array
    cout << "Expanded array: ";
    for (int i = 0; i < 2 * SIZE; i++) {
        cout << expandedArr[i] << " ";
    }
    cout << endl;

    // Free memory
    delete[] arr;
    delete[] expandedArr;

    return 0;
}