Question: (C lenguage ) Write a program to perform various array operations. Your program should prompt the user for the array operation and based on the
(C lenguage ) Write a program to perform various array operations. Your program should prompt the user for the array operation and based on the operation it should prompt the user for the necessary inputs from the user, perform the operation, and then display the result. Array operations: 1. Sum the elements in an array 2. Increment the elements in an array by one. Change the array values in place (change the elements of the original array). 3. Take the absolute value of the elements in an array (if an array element is negative, negate it). Change the array values in place (change the elements of the original array). 4. Scalar multiply multiply the elements of the array by a number (scalar) and store the results in another array. 5. Window average for a given window size (a window is a small section of the array), slide the window down the array and compute the average of the elements for each window and store the results in another array (see example below). 6. Exit stop performing operations Your main function should continuously loop until the user selects the Exit operation (6). Within the loop, your main function should call a function to display the array operation options and input the operation, then use a switch statement to control the operation to be performed. For each case (array operation option), the program should prompt the user for the various inputs (using the input_array function to input arrays), perform the operation (by calling the appropriate function), and then display the corresponding result (using the print_array function if needed). When inputting an array, if the user inputs too many values (more than the size of the array), the program should exit (use the exit function with EXIT_FAILURE). You should develop each of the following functions to use in your program. Function: input_operation Description: Display a menu of the different array operation options, input the option, check if it is a valid option and if so, return the option. If the user enters an invalid option the program should loop (use while loop) until the user enters a valid option. Input parameters: none 2 Return value: array operation option (1 = sum, 2 = increment, 3 = absolute, 4 = scalar multiply, 5 = window average, 6 = exit)
Function: input_array Description: input an integer array until a 99999 is encountered. If the user enters more than max numbers, the function should exit with EXIT_FAILURE. Input parameters: address of int array, max size of array Return value: size of array
Function: print_array Description: print the elements of the array Input parameters: address of int array, size of array (N) Return value: none
Function: sum_array Description: sum the elements in the array Input parameters: address of int array, size of array Return value: sum of the elements in the array (N) Ex: array values before function call: 0, 5, 7, 9 N = 4 sum returned: 1
Function: increment_array Description: increment the elements in the array by one Input parameters: address of int array, size of array (N) Return value: none Ex: array values before function call: 0, 5, 7, 9 N = 4 array values after function call: 1, 4, 8, 10
Function: absolute_array Description: replace the negative values in the array with the absolute value. Input parameters: address of int array, size of array (N) Return value: none Ex: array values before function call: 0, 5, 7, 9 N = 4 array values after function call: 0, 5, 7, 9
Function: scalar_multiply Description: multiply the elements of the array by a number (scalar) Input parameters: address of input int array, size of array (N), integer scalar, address of the resulting int array Return value:none 3 Ex: array values of input array: 0, 5, 7, 9 N = 4, scalar = 5 array values of resulting array: 0, 25, 35, 45
Function: window_avg Description: compute the average of the values of a window of win_size elements within the array. The average value should be aligned to (stored at the index that corresponds to) the middle element of the window (see below). Note, the win_size should be an odd number so that there is a middle element. Hint: you need to use nested loops. Input parameters: address of int array, size of array (N), window size (win_size), address of float array containing averages Return value:none Ex: int array values before function call: 0, 5, 7, 9, 2, 4 N = 4, win_size = 3 average array values after function call: 0.0, 0.67, 3.67, 6.0, 5.0, 0.0 1st window: 0, 5, 7 average(0,5,7) = (0 + 5 + 7)/3 = 0.67 2nd window: 5, 7, 9 average(5,7,9) = (5 + 7 + 9)/3 = 3.67 3rd window: 7, 9, 2 average(7, 9, 2) = (7 + 9 + 2)/3 = 6.0 Etc.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
