Question
- Write a program that performs several operations on an array of positive ints. The program should prompt the user for the size of the
- Write a program that performs several operations on an array of positive ints. The program should prompt the user for the size of the array (validate the size) and dynamically allocate it. Allow the user to enter the values, do not accept negative values in the array. - Your program should then define the functions described below, call them in order, and display the results of each operation: a) reverse: This function accepts a pointer to an int array and the size of the array. The function creates a copy of the received array and stores the elements in reverse order. Return a pointer to the new array. b) expand: This function accepts a pointer to an array (the original array), a pointer to the reversed array, and the size of the array as its parameters. The function should create a new array that is twice the size of the argument arrays. The function should copy the contents of the original array to the new array in the first half and the reversed array in the second half. The function should then return a pointer to the new array. c) shift: This function accepts a pointer to an array and the size of the array. The function should create a new array that is two elements larger than the argument array. Store -1 in the first two elements of the new array. The rest of the elements will be shifted by two to the right; first element of the argument array will be third element in the new array, second element of the argument array will be fourth element in the new array, and so on. The function should return a pointer to the new array. d) mode: This function accepts a pointer to an array and its size as parameters and finds the mode in that array. The mode is the element that occurs the most. If the array has no mode, the function should return -1.
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