Question

In: Computer Science

C++ Write the implementation of the function concatenateIntArrays. This function receives 4 parameters in the following...

C++

Write the implementation of the function concatenateIntArrays. This function receives 4 parameters in the following order:

  1. An array of integer values (array1).
  2. An integer representing the size of array1 (size1).
  3. An array of integer values (array2).
  4. An integer representing the size of array2 (size).

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:

  • array1[]={1,2,3,4,5};
  • array2[]={6,7};
  • size1 = 5;
  • size2 = 2;

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

Solutions

Expert Solution

#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);
}


Related Solutions

"sum_between" function Write a function named "sum_between" that receives 2 parameters - "start" (an int) and...
"sum_between" function Write a function named "sum_between" that receives 2 parameters - "start" (an int) and "end" (an int). It should return the sum (total) of all of the integers between (and including) "start" and "end". If "end" is less than "start", the function should return -1 instead. e.g. if you give the function a start of 10 and an end of 15, it should return 75 (i.e. 10+11+12+13+14+15)
C++ Write the definition of a function minMax that has five parameters. The first three parameters...
C++ Write the definition of a function minMax that has five parameters. The first three parameters are integers. The last two are set by the function to the largest and smallest of the values of the first three parameters. The function does not return a value. The function can be used as follows: int a=31, b=5, c=19 big, small; minMax(a,b,c,&big,&small); /* big is now 31 */ /* small is now 5 */ **ONLY THE FUNCTION
Write in C++ Print the following heading (should be in heading function) Welcome to Reference parameters...
Write in C++ Print the following heading (should be in heading function) Welcome to Reference parameters 2 ) ask the user for 2 numbers (should be in main) 3 ) Calculate the sum and product of the numbers using reference parameters (should be in getAnswer function) 4 ) Print the sum and product of the numbers in the following format: (should be in printmessage function) Here is the function you need        Function name | Parameters                       | Return Type    heading |...
Write a Python program: The function is named validity(). It receives 2 floating point parameters, min...
Write a Python program: The function is named validity(). It receives 2 floating point parameters, min and max, from the program that invoked it. The function asks the user to enter a float number. Using a while loop it checks whether the number is valid (between min and max, inclusive). If not valid, the while loop uses this statement to prompt for a new number: num = float (input (" Enter a number that is at least :"+ str(min) +...
A tree can be considered as a structured graph. Write a C++ function that receives a...
A tree can be considered as a structured graph. Write a C++ function that receives a BST object and returns its corresponding graph representation, implemented via an adjacency list. What will be the impact on the search complexity?
Write a C++ function, smallestIndex, that takes as parameters an int array and its size and...
Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns the index of the first occurrence of the smallest element in the array. Write another C++ function,lastLargestIndex, that takes as parameters an int array and its size and returns the index of the last occurrence of the largest element in the array. An analysis and design of the function smallestIndex is given below. Write an analysis and design for the function lastLargestIndex. Write...
Write a C++ function, smallestIndex, that takes as parameters an int array and its size and...
Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns the index of the first occurrence of the smallest element in the array. Also, write a program to test your function. You must write our commands in the middle: Write a C++ Program: #include <iostream> using namespace std; const int ARRAY_SIZE = 15; void printArray(const int x[], int sizeX); int smallestIndex(const int x[], int sizeX); int main() {      int list[ARRAY_SIZE] = {56,...
Write a function that will accept two integer matrices C and D by reference parameters. The...
Write a function that will accept two integer matrices C and D by reference parameters. The function will compute the transpose of C and store it in D. For your information, the transpose of matrix C is D, where D[j][i] = C[i][j]. [7 marks] Explain the time complexity of this function inside of the function code as a comment. [3 marks] in C++
Write a function in c++, called afterAll that takes two parameters, a vector of string and...
Write a function in c++, called afterAll that takes two parameters, a vector of string and a string. The function returns true if the 2nd parameter comes after all of the strings in the vector, order-wise, false if not. As an example, "zoo" comes after "yuzu".
In C++ Write a function which takes two parameters: an array of ints and an int...
In C++ Write a function which takes two parameters: an array of ints and an int size of the array and prints every element greater than 5 to the screen. As an example, if the array has the following 10 elements: 2 5 8 9 7 1 0 2 6 3, your function should print out 8 9 7 6. You may assume that the parameters passed to the function are valid. Your function must have the following signature: void...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT