//Cecilia Rangel CSC5 Chapter 9, P.539, #12
//
/**************************************************************
*
* SHIFT ELEMENT ARRAY
* ____________________________________________________________
* This program creates an array of intergers, then creates a
* shifted array of elements thats shifted one space to the
* right changing the first number to 0.
*
*_____________________________________________________________
*
* OUTPUT
* Array : OUTPUT a array shifted once
* to the right
* ***************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
//Prototype functions
int *duplicateArray(const int*, int);
void displayArray(int[], int);
int main()
{
const int SIZE = 5;
int array[SIZE] = {1, 2, 3, 4, 5};
int *duplicate;
duplicate = duplicateArray(array, SIZE);
cout << "Orginal Array: " << endl;
displayArray(array, SIZE);
cout << endl << "Duplicate Array: " << endl;
displayArray(duplicate, SIZE);
delete[] duplicate;
duplicate = 0;
return 0;
}
/****************************************************************************
* duplicateArray
* __________________________________________________________________________
* This function takes the orginal array and then shifts the elements the left
* and changes element[0] to 0.
* **************************************************************************/
int *duplicateArray(const int *array, int SIZE)
{
int *newArray;
if(SIZE <= 0)
{
return NULL;
}
newArray = new int[SIZE + 1];
newArray[0] = 0;
for (int i = 0; (i + 1) < SIZE; i++)
{
newArray[i + 1] = array[i];
}
return newArray;
}
/****************************************************************************
* displayArray
* _________________________________________________________________________
* A function that will be used in main to display the orginal array and the
* new duplicate array.
* *************************************************************************/
void displayArray(int array[], int SIZE)
{
for (int i = 0; i < SIZE; i++)
{
cout << array[i];
}
}