Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PLEASE COMMENT ON EACH CODE BLOCK. Also read the hints. Thanks! Write a C++ program which takes as input two arrays from the user and
PLEASE COMMENT ON EACH CODE BLOCK. Also read the hints. Thanks!
Write a C++ program which takes as input two arrays from the user and performs element wise multiplication of the two arrays following which it would display the resultant array. Both arrays will have the same number of elements. Your program should ask the user for the length of the arrays, and then populate both arrays by further querying the user for input. This assignment explores operations with partially filled arrays. Your program should declare arrays with a maximum size of 20. The user can choose the length of arrays from size 1 up to 20 elements. For Arrays A = [Ax, Ay, Az] and B = [Bx, By, B2] of length 3, the resultant array C =[Ax*Bx, Ay* By, Az*B2] For example, your program will first ask for the number of elements N in the arrays. If the user provided N = 4, your program would take 4 numbers as input for the FIRST array, followed by 4 numbers for the SECOND array. Here, we are working with arrays with 4 numbers each. Let's say the user gave the following values for each array: FIRST array = [2, 4, 6, 8], SECOND array = [11, 12, 13, 17] Your program should compute the element wise multiplication of both arrays and display the resultant array. RESULT array would be computed as [2*11, 4*12, 6*13, 8*17] = 122, 48, 78, 136], where: 1. The first elements from both arrays (2 and 11) are multiplied and the result (22) is stored in the first location of the RESULT array. RESULT array = [22, 2. The second elements (4 and 12) would be multiplied and the result (48) is stored in the second location of the RESULT array. RESULT array = [22, 48,] 3. The third elements (6 and 13) are multiplied and the result (78) is stored in the third location of the RESULT array. RESULT array = [22, 48, 78,] 4. Finally, the fourth elements (8 and 17) are multiplied and the result (136) is stored in the fourth location of the RESULT array. RESULT array = 122, 48, 78, 136] Once the RESULT array is computed, your program will then display this resultant array to the user. The same procedure applies for arrays of larger sizes. Your program will allow arrays with a maximum length of 20. Make sure your code works for any input number, not just the test cases. Your code will be tested on other test cases not listed here. Make sure your output matches the formatting as shown in the test cases below. Please properly comment your code before submission. Sample Test cases: Sample Test Case 1: Please Enter Number of elements: 4 Please Enter elements for the FIRST array: Please Enter elements for the SECOND array: The RESULT is: 14, 15, 18, 15 Sample Test Case 2: Please Enter Number of elements: 2 Please Enter elements for the FIRST array: 12 Please Enter elements for the SECOND array: The RESULT is: 240, 20 Sample Test Case 3: Please Enter Number of elements: 25 Out of range, Please Enter number of elements from 1 up to 20 Sample Test Case 4: Please Enter Number of elements: 10 Please Enter elements for the FIRST array: Please Enter elements for the SECOND array: The RESULT is: 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 HINTS: We can use loops for this exercise All our loops will execute N number of times, where N is the number of elements in the array N cannot exceed 20. So we can declare our arrays similar to int arr[20], but use partially filled arrays up to N
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started