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}

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

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}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education