//Charlotte Davies-Kiernan CS1A Chapter 9 P. 539 #11
//
/******************************************************************************
*
* Compute Expansion of Array
* ____________________________________________________________________________
* This program will accept an array of integers the size being the users
* choice, the program will then produce a new array that is twice as large.
* The unused elements in the new array will ne initialized with 0.
* ____________________________________________________________________________
* Input
* size :amount of elements featured in original array
* arr :integers entered by user to make up the original array
* Output
* expanded :new array that is oduble the original amount the user entered
*****************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
//Function Protoype
int* expandArray(int* arr, int size);
int main() {
//Data Dictionary
int size;
int* arr;
int* expanded;
//Prompt User
cout << "Enter the size of the array: " << endl;
cin >> size;
arr = new int[size];
cout << "Enter " << size << " integers: " << endl;
for(int i = 0; i < size; i++){
cin >> arr[i];
}
//Invoke Function
expanded = expandArray(arr, size);
//Display New Array
cout << "Expanded array (twice the size): " << endl;
for(int i = 0; i < size * 2; i++){
cout << expanded[i] << " ";
}
//Free Memory
delete[] arr;
delete[] expanded;
return 0;
}
//Function Definition
int* expandArray(int* arr, int size){
int* newArr = new int[size * 2];
for(int i = 0; i < size; i++){
newArr[i] = arr[i];
}
for(int i = size; i < size * 2; i++){
newArr[i] = 0;
}
return newArr;
}