Write a C++ program that will test function described below that use pointers and dynamic memory allocation.
Functions:
You will write the function described below. Then you will call them from the main function, to demonstrate their correctness.
concat_array: takes two int arrays and the arrays' sizes as arguments (that's 4 arguments). It should create a new array big enough to store both arrays. Then it should copy the contents of the first array to the new array, and then copy the contents of the second array to the new array in the remaining elements, and return a pointer to the new array.
OutPut:
testing concat:
Expected result: 1 2 3 4 5 6 7 8 9 0 11 22 33 44 55
Actualresult: 1 2 3 4 5 6 7 8 9 0 11 22 33 44 55
RULES:
DO NOT change the names of the functions!
DO NOT do any output from the functions (only from main)!
DO NOT do any input at all!
NOTES:
This program DOES need to be done in a Linux or Unix environment.
It is your responsibility to fully test your functions. They must work for ANY valid input. The main function you submit must have at least one test case for each function. However, you should test the functions over several different test cases to convince yourself that they work.
You do not need to use named constants for your test data (or array sizes) in this assignment, but you DO need to follow the rest of the style guidelines including function definition and comments.
Your program should release any dynamically allocated memory when it is finished using it.
you may want to include a function that displays the values of an int array on one line, separated by spaces, for displaying test arrays and results.
int* concat_array(int* arr1, int size1, int* arr2, int size2) {
int *result = new int[size1 + size2];
for(int i=0; i<size1; i++) {
result[i] = arr1[i];
}
for(int i=0; i<size2; i++) {
result[size1 + i] = arr1[i];
}
return result;
}
void printArray(int *arr, int size) {
for(int i=0; i<size; i++) {
cout << arr[i] << " ";
}
cout << endl;
}
int main() {
int arr3[] = {11, 22, 33, 44, 55};
int *result = concat_array(arr2, 10, arr3, 5);
cout << "testing concat:" << endl;
cout << "Expected result: 1 2 3 4 5 6 7 8 9 0 11 22 33 44 55" << endl;
cout << "Actual result: ";
printArray(result, 15);
}
Write a C++ program that will test function described below that use pointers and dynamic memory...
C++ Project - Create a memory game in c++ using structs and pointers. For this exercise, you will create a simple version of the Memory Game. You will again be working with multiple functions and arrays. You will be using pointers for your arrays and you must use a struct to store the move and pass it to functions as needed. Program Design You may want to create two different 4x4 arrays. One to store the symbols the player is...
Complete the following program based on the comments inside. Important note: You are only allowed to use the new operator in solving this problem. (i.e. Don't use predefined array functions such as append(), concat(), etc. in solving this problem) Important Note 2: Your program should work the same if the sizes of first_array and second_array are changed. (i.e. make use of the .length variable to get the length of the arrays) void setup () { int [] first_array = {11,...
c++ program8. Array/File Functions Write a function named arrayToFile. The function should accept three arguments: the name of a file, a pointer to an int array, and the size of the array. The function should open the specified file in binary mode, write the contents of the array to the file, and then close the file. Write another function named fileToArray. This function should accept three argu- ments: the name of a file, a pointer to an int array, and the size...
I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...
array function
• Create a function called show2D.
• This function should accept a two-dimensional array as parameter
and display its contents that are odd numbers on the screen.
• This function should work with any of the following arrays of
different sizes:
int hours[3][9];
int stamps[7][9];
int cities[15][9];
• Write a demo program to show how to use the function
show2D.
this is c++ program
Task 2: Array functions • Create a function called show2D. • This function should...
Given below is a partially completed C program, which you will use as a start to complete the given tasks. #define SIZE 9 #include <stdio.h> int compareAndCount (int[], int[]); double averageDifference (int[], int[]); void main() { } int compareAndCount(int arr1[SIZE], int arr2[SIZE]) { int count - @; for (int i = 0; i < SIZE; i++) { if (arri[i] > arr2[i]) count++; return count; Task 1: (10 pts) Show the design of the function compareAndCount() by writing a pseudocode. To...
(C++)Write a function that accepts an int array and the array’s size as arguments.The function should create a new array that is twice the size of the argument array.The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0.The function should return a pointer to the new array.Demonstrate the function by using it in a main program that reads an integer N (that is not more...
Please help :)
Problem 1: Complete separately Dr. Rocklino a) Write a program in which the main method creates two arrays, each with 10 int slots. main initializes the first array to randomly generated integers. It then calls a method named copy, passing it the two arrays. Your copy method copies the contents of the first array to the second array. It then returns to main. main then displays the contents of both arrays. b) Write a program in which...
- Write a program that performs several operations on an array of positive ints. The program should prompt the user for the size of the array (validate the size) and dynamically allocate it. Allow the user to enter the values, do not accept negative values in the array. - Your program should then define the functions described below, call them in order, and display the results of each operation: a) reverse: This function accepts a pointer to an int array...
IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to 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...