Hi All, I'm stuck on my C++ assignment. I have no idea how to finish it...I think I'm missing something in my code such as how to double the size of the argument array and copy it, then initialize the unused elements of the second array with 0. thanks in advance
Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0. The function should return a pointer to the new array. Demonstrate the function in a complete program. Print the contents of the array inside the main function.
Here's my code
#include "stdafx.h"
#include <iostream>
using namespace std;
void showValues(int[], int); // Function prototype
int main()
{
const int SIZE = 4;
int numbers[SIZE] = {1, 2, 3 ,4};
showValues(numbers, SIZE);
// Twice the size of argument array
int * dynamic;
dynamic = new int[SIZE * 2];
// Copy to the content
for(int i = 0; i < SIZE; i++)
for(int j = SIZE; j < SIZE * 2; j++)
cout << endl;
return 0;
}
//***************************************************
// Definition of function showValue. *
// This function accepts an array of integers and *
// the array's size as its arguments. The contenets *
// of the array are displayed. *
//***************************************************
void showValues(int nums[], int size)
{
for(int index = 0; index < size; index++)
cout << nums[index] << " ";
cout << endl;
}