Question: Create a program with the following requirements: Create a new project/solution called arrays . The file arrays.cpp is created for you automatically. Many functions will

Create a program with the following requirements:

Create a new project/solution called arrays. The file arrays.cpp is created for you automatically.

Many functions will be written for this laboratory, but this time they will be written into separate files. Your main program will reside in the arrays.cpp file. Two additional files will be created: arrayFunctions.h and arrayFunctions.cpp (or .c instead of .cpp if you are using a true C compiler like Codeblocks or XCODE). The header file arrayFunctions.h should contain your function prototypes. The source file arrayFunctions.cpp (or arrayFunctions.c for Codeblocks/XCODE) will contain all of your source code. Separate instructions for creating these files is on Blackboard. When all is setup correctly, you can just #include your .h file (NOT your .cpp or .c file!) to access your functions.

In the end, the main program (arrays.cpp) will resemble this format:

#include stdafx.h

#include arrayFunctions.h

int main( )

{

// Declare variables, arrays, etc.

// Call functions, pass arrays as inputs

// Print results

return 0;

}

List of functions (note: your functions must work for any sized array, the size should be passed into each function as a parameter).

Write a function called randomizeArray( ) that fills an array with random data in the range specified by low_val and high_val. the maximum value found in the array. Essentially the lowest possible random number should be low_val and the highest should be high_val. The prototype for this function will be

void randomizeArray(int nums[ ], int array_size, int low_val, int high_val);

Write a function called countElements( ) that checks an array to find out how many of the array elements have a value in the range of low_val to high_val. The low_val and high_val are passed in, and the function returns the integer number of elements that fall in this range. The prototype for this function will be

int countElements(int nums[ ], int array_size, int low_val, int high_val);

Write a function called getMax( ) that returns an integer representing the maximum value found in the array. The prototype for this function will be int getMax(int nums[ ], int array_size);

Write a function called getMin( ) that returns an integer representing the minimum value found in the array. The prototype for this function will be int getMin(int nums[ ], int array_size);

Write a function called printArray( ) that prints the array, with one column showing the array element number and another column showing the value of each element. The prototype for this function will be void printArray(int nums[ ], int array_size);

Write a function called sortAscending( ) which sorts the array in ascending order. The prototype for this function will be void sortAscending(int nums[ ], int array_size);

Write a function called sortDescending( ) which sorts the array in descending order. The prototype for this function will be void sortDescending(int nums[ ], int array_size);

Write a function called setArray( ) which allows a user to enter values for the array. The prototype for this function will be void setArray(int nums[ ], int array_size);

Write a function called getMedian( ) which returns the middle value for an array. The prototype for this function will be int getMedian(int nums[ ], int array_size);

Write a function called getAverage( ) which returns the floating point average of all the elements of the array. The prototype for this function will be float getAverage(int nums[ ], int array_size);

Write a function called copyArray( ) which copies the contents of one array to another. The prototype for this function will be void copyArray(int array1[ ], int array2[ ], int array_size);

Write a function called searchArray( ) which accepts an integer element to be searched for in the array. The function will return the index of the first element that is found to match an element of the array. In simpler words, the function searches an array to see if a particular search item is present in the array. If the value is not found in the array, then the function returns -1. The prototype for this function will be int searchArray(int search_val, int array[ ], int array_size);

Use your main program to declare an array of arbitrary length, then use that array as a parameter in each of the above functions. Verify that your functions work correctly for different array sizes.

For demonstration, show the output of each function. Print individual integers for min, max, and median. Show an example of the searchArray function where a value is found and then one for when a value is not found in the array. Print a single float value for the average. Use the printArray( ) to print the original array and then the copied array. Then use printArray( ) again after each sorting function is called.

Show the contents of arrayFunctions.h and arrayFunctions.cpp separetly.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!