Create a function which combines the elements of two arrays into one (omitting all repeating values). You will also need

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Create a function which combines the elements of two arrays into one (omitting all repeating values). You will also need

Post by answerhappygod »

Create A Function Which Combines The Elements Of Two Arrays Into One Omitting All Repeating Values You Will Also Need 1
Create A Function Which Combines The Elements Of Two Arrays Into One Omitting All Repeating Values You Will Also Need 1 (160.87 KiB) Viewed 68 times
Create A Function Which Combines The Elements Of Two Arrays Into One Omitting All Repeating Values You Will Also Need 2
Create A Function Which Combines The Elements Of Two Arrays Into One Omitting All Repeating Values You Will Also Need 2 (278.91 KiB) Viewed 68 times
Create a function which combines the elements of two arrays into one (omitting all repeating values). You will also need to create /use a helper function which will determine if an array has a certain value in it or not. Both of these functions are to be written within one source file. See next page of more details on requirements and tips. Function 1-isNumberInArray: Given two arguments, first an integer and second an integer array, this function will determine whether or not the array parameter contains an element with the same value as the integer parameter. If so, it'll return true, otherwise, it'll return false. int list [] = {1, 2, 3); isNumber InArray(2, list); isNumber InArray(4, list); //Returns true, 'list' does have 2. //Returns false, 'list' doesn't have 4. Function 2-unionArrays: Given two integer array arguments, this function will return an integer array which contains the union of both arrays elements (as seen in sample on last page). • Your union array must NOT contain ANY duplicate elements o For example, a union of {1, 2, 2} and {2, 3) should NOT result in this: {1, 2, 2, 2, 3} You MUST utilize the "isNumberInArray" function in this function's body/ implementation Your union array DOESN'T need to be sorted • Your union array doesn't need to be of perfect length, you can set the size of the union array to just be the sum of the parameter arrays' sizes. This also means you don't need to worry about the "trailing zeros" your union array result may have o For example, a union of {1, 2, 3} and {2, 3, 4} resulting in {1, 2, 3, 4, 0, 0} is okay • Your union array CANNOT have any "gaps" in it, so for example, a union of {1, 2, 3) and (3, 4, 5} shouldn't look like this {1, 2, 3, 0, 4, 5), nor this {1, 2, 0, 3, 4, 5}
Requirements: 1. As per usual, be sure to leave some comments (in your code) on how certain complex/ unique parts of your program work. 2. Be sure to follow the instructions outlined for each function EXACTLY as described. This includes small things such as making sure your functions are defined with the right names (and are spelled correctly), using the appropriate/ necessary data type for your parameter(s)/ return type, etc. 3. Both functions MUST exist in the same source file. DO NOT create separate files for each function. 4. Your final solution should NOT have any print statements anywhere in the file. You can of course utilize print statements to test your code/numbers as your developing this program, just be sure to delete them once your done. 5. DO NOT use the '...' operator anywhere in your functions' parameter list. Tips: 1. Your main method does NOT need to have any code in it. Ideally, you would use it for testing purposes to see if the return results of different function calls (with varying arguments) works out as expected What's important for this assignment is that all the function definitions you create are formatted correctly and work as expected. o I also recommend you create a "printArray" function to help you examine your arrays when testing/debugging your code 2. This assignment doesn't require the use of multi-dimensional arrays (nor should it) 3. Finish the "is Number InArray" function first, as that is really easy to implement. 4. As for the "unionArrays" function: o Use for-each loops . I also recommend you establish a variable beforehand to keep track of the union array's index as more elements are assigned into it. Think back to how loops and variables work and how you can use them to your advantage here. o o You can assume that the arguments will never have element value(s) of zero. As stated in the guidelines above, your union array doesn't need to be of perfect length, so when you're defining it, have the size declaration (of your union array) just be based of the sum of the two array parameters' lengths ▪ IE. int unionArray[] = new int [ <length_1>+<length_2> ];
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply