Question: Write a C++ program that prompts the user for two integer arrays and their size. If the size entered by the user is less than
Write a C++ program that prompts the user for two integer arrays and their size. If the size entered by the user is less than or equal to zero, ask the user to input again. Then, the program should have three functions described below:
- dotProduct(...arguments here...): This function has the 2 integer arrays and their size as arguments (for a total of 3 arguments). Compute and return the dot product of these 2 arrays. You must print the dot product from your main() function. The dot product can be found by adding the products of each element of the arrays. Do NOT use array brackets when accessing the element values of your arrays in this function (use pointers instead).
+ Ex. Array 1: [1,2,3,4] and Array 2: [3,3,4,6]
+ Dot Product= ((1*3) + (2*3)+ (3*4)+ (4*6))= 45
- alternate(...arguments here...): This function also takes 2 integer arrays and their size as arguments (for a total of 3 arguments). Print the elements of both of these arrays by alternating the elements of each array. Use array brackets to access the elements for this function.
+ Ex. Array 1: [1,2,3,4] and Array 2: [5,6,7,8]
+ It should print: [1,5,2,6,3,7,4,8]
- negatives(...arguments here...): This function takes in 2 integer arrays and their size as arguments (for a total of 3 arguments). Change the value of each array to its additive inverse (its negative). You may choose the way you want to access the elements of the array. Print both arrays from your main() function.
+ A number, N, is the additive inverse of a number, N, if it satisfies the property: N + N = 0
+ Ex. Array 1: [-1,2,3,-4]
+ Your program should change the array values with new values: [1,-2,-3,4] These functions must be called from your main() function.
The sample output should like this
Enter Array size: -3 Incorrect array size. Try Again Enter Array size: Incorrect array size. Try Again Enter Array size: 4 Begin Entering Array Elements Array 1: Enter element: 1 Enter element: 2 Enter element: 3 Enter element: 4 Array 2: Enter element: 5 Enter element: 6 Enter element: 7 Enter element: 8 The dot product is: 70 Alternating Array: [1, 5, 2, 6, 3, 7, 4, 8] Negative Array 1: [-1, -2, 3, -4] legative Array 2: [-5, 6, 7, -8] Press any key to continue
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
