Question: Write a C++ function that examines an array and finds array n that is embedded in orig. It returns that as a new array using
Write a C++ function that examines an array and finds array n that is embedded in orig. It returns that as a new array using dynamic memory.
Assume in another function we joined two arrays together with the size of the new array as the first element. We want to get the separate arrays again n = 1 stands for Array 1 and n = 2 stands for Array 2
Arr1 = {5, 1,2,3,4}
Arr2 = {5, 10, 20, 30, 40 };
NewArr = { 11, 5, 1, 2, 3, 4, 5, 10, 20, 30, 40 }
The original l two arrays have their sizes as the first element.
Example orig: { 11, 5, 1, 2, 3, 4, 5, 10, 20, 30, 40 } n: 1 This would return a new dynamically allocated array with the values: {5,1,2,3,4} Example 2 orig: { 11, 5, 1, 2, 3, 4, 5, 10, 20, 30, 40 } n: 2 This would return a new dynamically allocated array with the values: {5,10,20,30,40}
n represents the array number that is embedded in the array
Use this function prototype:
short int * GetArrN(short int* orig, int n) {
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
