In: Computer Science
C++
Write the implementation of the function concatenateIntArrays. This function receives 4 parameters in the following order:
The function creates a dynamic array of integers of size
size1+size2 to store all the values in array1,
followed by all the values in array2. The function returns
the pointer used to create the dynamic array of integers.
Example:
Given the two arrays of integers:
The dynamic array of integers created by your function must be
and array size 7 with the following values:
1,2,3,4,5,6,7
#include <iostream>
using namespace std;
void concatenateIntArrays(int array1[],int sizea1,int array2[],int
sizea2){
int n = sizea1 + sizea2;
int array3[n];
for(int i=0;i<sizea1;i++){
array3[i] = array1[i];
}
for(int i=0;i<sizea2;i++){
array3[sizea1+i] = array2[i];
}
//DYNAMIC ARRAY
int *arr = new int(n);
for(int i=0;i<n;i++){
arr[i] = array3[i];
cout<<arr[i]<<",";
}
}
int main() {
int array1[] = {1,2,3,4,5};
int array2[] = {6,7};
int sizea1 = sizeof(array1)/sizeof(array1[0]);
int sizea2 = sizeof(array2)/sizeof(array1[0]);
// cout<<sizea1<<" "<<sizea2<<endl;
concatenateIntArrays(array1,sizea1,array2,sizea2);
}