//Charlotte Davies-Kiernan CS1A Chapter 9 P.539 #12
//
/******************************************************************************
*
* Compute Element Shifter
* ____________________________________________________________________________
* This program will accept an array that is inputted by the user and then
* display a new array that is led by zero as the first element and the
* remaining elements will be shifted over one from the original array.
* ____________________________________________________________________________
* Input
* size :amount of elements user decides
* arr :integers that make up the array chosen by user
* Output
* newArr :new array leading with 0
*****************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
//Function Prototype
int* addLeadingZero(int* arr, int size);
int main() {
//Data Dictionary
int size;
int* arr;
int* newArr;
//User Input
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
newArr = addLeadingZero(arr, size);
//Display New Array
cout << "New array (1 element larger, starting with 0): " << endl;
for(int i = 0; i < size + 1; i++){
cout << newArr[i] << " ";
}
//Free Memory
delete[] arr;
delete[] newArr;
return 0;
}
//Function Definition
int* addLeadingZero(int* arr, int size){
int* newArr = new int[size];
newArr[0] = 0;
for(int i = 0; i < size; i++){
newArr[i + 1] = arr[i];
}
return newArr;
}