C++ Write a function that accepts an array and its size as arguments, creates a new array that is a copy of the argument array, and returns a pointer to the new array. Display the array in main(). The function will work as follows: Accept an array and its size as arguments. Dynamically allocate a new array that is the same size as the argument array. Copy the elements of the argument array to the new array. Return a new pointer to the new array. // This program uses a function to duplicate// an int array of any size.#include using namespace std;// Function prototype_________________________________________________int main(){ // Define constants for the array sizes. const int SIZE1 = 5, SIZE2 = 7, SIZE3 = 10; // Define three arrays of different sizes. int array1[SIZE1] = { 100, 200, 300, 400, 500 }; int array2[SIZE2] = { 10, 20, 30, 40, 50, 60, 70 }; int array3[SIZE3] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // Define three pointers for the duplicate arrays. int *dup1 = nullptr, *dup2 = nullptr, *dup3 = nullptr; // Duplicate the arrays. dup1 = duplicateArray(array1, SIZE1); dup2 = duplicateArray(array2, SIZE2); dup3 = duplicateArray(array3, SIZE3); // Display the original arrays. cout << "Here are the original array contents:\n"; displayArray(array1, SIZE1); displayArray(array2, SIZE2); displayArray(array3, SIZE3); // Display the new arrays. cout << "\nHere are the duplicate arrays:\n"; displayArray(___________); displayArray(___________); displayArray(___________); // Free the dynamically allocated memory and // set the pointers to 0. _________________ _________________ _________________ _________________ _________________ _________________ return 0;} The duplicateArray function accepts an int array *// and an int that indicates the array's size. The *// function creates a new array that is a duplicate *// of the argument array and returns a pointer to the *// new array. If an invalid size is passed the *// function returns null. nt *duplicateArray(const int *arr, int size){ //complete the function}//**************************************************// The displayArray function accepts an int array *// and its size as arguments and displays the *// contents of the array. *//**************************************************void displayArray(const int arr[], int size){ //complete the function}
C++
Write a function that accepts an array and its size as arguments, creates a new array that is a copy of the argument array, and returns a pointer to the new array. Display the array in main().
The function will work as follows:
- Accept an array and its size as arguments.
- Dynamically allocate a new array that is the same size as the argument array.
- Copy the elements of the argument array to the new array.
- Return a new pointer to the new array.
// This program uses a function to duplicate// an int array of any size.#include <iostream>using namespace std;// Function prototype_________________________________________________int main(){ // Define constants for the array sizes. const int SIZE1 = 5, SIZE2 = 7, SIZE3 = 10; // Define three arrays of different sizes. int array1[SIZE1] = { 100, 200, 300, 400, 500 }; int array2[SIZE2] = { 10, 20, 30, 40, 50, 60, 70 }; int array3[SIZE3] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // Define three pointers for the duplicate arrays. int *dup1 = nullptr, *dup2 = nullptr, *dup3 = nullptr; // Duplicate the arrays. dup1 = duplicateArray(array1, SIZE1); dup2 = duplicateArray(array2, SIZE2); dup3 = duplicateArray(array3, SIZE3); // Display the original arrays. cout << "Here are the original array contents:\n"; displayArray(array1, SIZE1); displayArray(array2, SIZE2); displayArray(array3, SIZE3); // Display the new arrays. cout << "\nHere are the duplicate arrays:\n"; displayArray(___________); displayArray(___________); displayArray(___________); // Free the dynamically allocated memory and // set the pointers to 0. _________________ _________________ _________________ _________________ _________________ _________________ return 0;}
The duplicateArray function accepts an int array *// and an int that indicates the array's size. The *// function creates a new array that is a duplicate *// of the argument array and returns a pointer to the *// new array. If an invalid size is passed the *// function returns null.
nt *duplicateArray(const int *arr, int size){ //complete the function}//**************************************************// The displayArray function accepts an int array *// and its size as arguments and displays the *// contents of the array. *//**************************************************void displayArray(const int arr[], int size){ //complete the function}

Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images









