Question
Notes: The function should accept three parameters: an input array of double-precision floating point values; an integer that specifies the number of usable elements in
Notes:
The function should accept three parameters: an input array of double-precision floating point values; an integer that specifies the number of usable elements in the input array; and an output array of integer values that is guaranteed to have enough space to store values at positions ranging from 0 to 15, inclusive.
The floating point input values are guaranteed to be greater than or equal to 0 and have a whole number part that is less than or equal to 15.
The function must truncate each floating point value in the input array to obtain an integer, and count how many times each integer in the range 0 to 15 shows up in the resulting list of truncated values. The number of occurrences of each value i should be stored at position i in the output array.
The function should not perform any input or output operations.
Before counting input values, you will need to reset all elements of the output array to zero as the array is not guaranteed to have been initialised beforehand.
Compile with the flags -Wall -Werror -std=gnu99 to ensure that your local settings match those used on the AMS.
Include the complete create_hist function as part of your submission. Ensure that an appropriate parameter list and result type have been inserted. Without these, your submission will not compile on the server.
Use this test driver to implement and test your function prior to submission. You can replace the array elements with specific values copied from your AMS transcript to help diagnose the cause of errors.
#include#include #include #include #include #include #include INSERT_RESULT_TYPE_HERE create_hist( INSERT_FORMAL_PARAMETERS_HERE ) { // TODO: INSERT CODE HERE } void call_function( const char * label, double x[], int count ) { int hist[15 + 1]; create_hist( x, count, hist ); printf( "%s ", label ); printf( "\tInput data: " ); for ( int i = 0; i < count; i++ ) { printf( "\t%d\t%f ", i, x[i] ); } printf( "\tHistogram: " ); for ( int i = 0; i <= 15; i++ ) { printf( "\t%d\t%d ", i, hist[i] ); } printf( " " ); } int main( void ) { srand( time( NULL ) ); double x1[] = { 0 }; call_function( "Count == 0", x1, 0 ); double x2[] = { 0, 0, 0 }; call_function( "Three equal values", x2, 3 ); double x3[15 + 1]; for ( int i = 0; i <= 15; i++ ) { x3[i] = i; } call_function( "One value in each bucket", x3, 15 + 1 ); double x4[15 * 2 + 1]; for ( int i = 0; i <= 15 * 2; i++ ) { x4[i] = (15+1) * ( double ) rand() / RAND_MAX; } call_function( "Random values", x4, 15 * 2 + 1 ); return 0; }
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