Question

This is for my Computer Programming class using Visual Studio C++ This is a home work...

This is for my Computer Programming class using Visual Studio C++ This is a home work assignment and is for a grade so answer seriously and if you don't know know or unsure don't answer I need the coding so i can copy and paste and need a screen shot of the result i can copy as well Thank You.

P1 – Merge two sorter arrays (80 points)

  1. (a) Write a function that receive two sorted arrays of integers and their sizes. Suppose the arrays are sorted in an increasing order. The function must merge the two arrays and return the merged sorted result. Use the following function header [40pts].

Int * mergeArrays (int * array1, int size1, int* array2, int size2)

(b) Write a main function to test the mergeArrays() function defined in part (a). In the main function create two arrays, not necessarily the same size. Print the arrays, then pass them as arguments to the mergeArrays() function and print the returned result. [40pts]

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

#include<iostream>
using namespace std;
  
// Merge arr1[0..n1-1] and arr2[0..n2-1] into
// arr3[0..n1+n2-1]
int * mergeArrays (int * array1, int size1, int* array2, int size2)
{
int i = 0, j = 0, k = 0;
int* arr3=new int[size1+size2];
// Traverse both array
while (i<size1 && j <size2)
{
// Check if current element of first
// array is smaller than current element
// of second array. If yes, store first
// array element and increment first array
// index. Otherwise do same with second array
if (array1[i] < array2[j])
arr3[k++] = array1[i++];
else
arr3[k++] = array2[j++];
}
  
// Store remaining elements of first array
while (i < size1)
arr3[k++] = array1[i++];
  
// Store remaining elements of second array
while (j < size2)
arr3[k++] = array2[j++];
return arr3;
}
  
// Driver code
int main()
{
int arr1[] = {1, 3, 5, 7};
int n1 = sizeof(arr1) / sizeof(arr1[0]);
  
int arr2[] = {2, 4, 6, 8};
int n2 = sizeof(arr2) / sizeof(arr2[0]);
  

int* arr3=mergeArrays(arr1,n1, arr2, n2);
  
cout << "Array after merging" <<endl;
for (int i=0; i < n1+n2; i++)
cout << arr3[i] << " ";
  
return 0;
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
This is for my Computer Programming class using Visual Studio C++ This is a home work...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Introduction: One of the most important uses of pointers is for dynamic allocation of memory. In...

    Introduction: One of the most important uses of pointers is for dynamic allocation of memory. In C++ there are commands that let the user request a chunk of memory from the operating system, and use this memory to store data. There are also commands to return memory back to the O/S when the program is finished using the data. In this lab, we will explore some of the things that can go wrong when using dynamic memory and discuss how...

  • please write me this program in C language Review UW files from the Internet can contain...

    please write me this program in C language Review UW files from the Internet can contain viruses. Unless you need to edit, it's safer to stay in Protected View View View - Word Terme MOHAMMED MUNTHER MOH Enable Editing Task # 3: Consider two integer arrays x and y of same size n with values: Xo, X1, X3,..., Xe1 and yo, yi, ya..... Yn-1 Write a function merge that receives array x and y and their size. It then returns...

  • Complete a program In C#: some code is included, you edit the areas that have not...

    Complete a program In C#: some code is included, you edit the areas that have not been filled. For your C# program you will complete code that plays the War card game. In this game, the deck of cards is evenly divided among two players. The players are not allowed to look at the cards in their hand. On each round of the game, both players lay down the top card from their hand. The player with the higher value...

  • c++ please no global varaible write a value returning function input data to dynamically allocate a...

    c++ please no global varaible write a value returning function input data to dynamically allocate a short array of size elements and store the input data entered from the disk file into array.Return the base address of the array allocated.Read the data from the text file Hello.txt and store the data in reverse order in the array.the size of the data set will be in the file size 10 and the data was 1 2 3 4 5 6 7...

  • 1. Write a C programme by using visual Studio: a) Write a function with parameters that...

    1. Write a C programme by using visual Studio: a) Write a function with parameters that returen the largest of three integer arguments. So users could call your function (name: max3) to output the maximum of three input values. b) Make a function outside of the main routine. And in the main routine, please call this function and print the harmonic mean. The harmonic mean of two numbers is obtained by taking the inverses of the two numbers, averaging them,...

  • Write a C++ program that simulates playing the Powerball game. The program will generate random numbers...

    Write a C++ program that simulates playing the Powerball game. The program will generate random numbers to simulate the lottery terminal generated numbers for white balls and red Powerball. The user will have the option to self-pick the numbers for the balls or let the computer randomly generate them. Set the Grand Prize to $1,000,000,000.00 in the program. Project Specifications Input for this project: Game mode choice – self pick or auto pick Five numbers between 1 and 69 for...

  • Programming in java In this part of this Lab exercise, you will need to create a...

    Programming in java In this part of this Lab exercise, you will need to create a new class named ArrayShiftMult. This class carries out simple manipulation of an array. Then you should add a main method to this class to check that your code does what it is supposed to do. 1. Create a BlueJ project named LAB06 as follows: a. Open the P drive and create a folder named Blue), if it does not exist already. Under this folder,...

  • Word Guessing Game Assignment Help Needed. This C++ (I'm using Visual Studio 2015) assignment is actually...

    Word Guessing Game Assignment Help Needed. This C++ (I'm using Visual Studio 2015) assignment is actually kind of confusing to me. I keep getting lost in all of the words even though these are supposed to instruct me as to how to do this. Can I please get some help as to where to start? Word guessing game: Overview: Create a game in which the user has a set number of tries to correctly guess a word. I highly recommend...

  • Lanuage C++ (Beginner level) Please...I need help with this assignment If I still have question, can...

    Lanuage C++ (Beginner level) Please...I need help with this assignment If I still have question, can i contact you? -------------------------- Program 1 - WRITE ALL THE CODE in ONE FILE...   MyArrayPtrArith1.cpp Step 1 - Define the class Write a class, myArrayClass, that creates an integer array. * Add an 'arraySize' variable, initialize to zero ( default constructor function ) * Create int * ptrArray ( default constructor set to NULL ) * Add a default constructor ( see above for...

  • Done in C++ using visual studio 1. Write a program with one additional function called int[]...

    Done in C++ using visual studio 1. Write a program with one additional function called int[] reverseArray(int array). This function will receive an array from main and then reverse and should return the reversed array to the main to print out. Use a single array and a single loop, you’re are neither allowed to print out just in reverse order nor allowed to use another array variable to store the original array in reverse order. 2. Write a program which...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT