Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help with this C programing This is staring code: int main(int argc, char **argv) { /* Local variables */ float f_array[NUM_TEST_ELEMENTS]; int i_array[NUM_TEST_ELEMENTS], i;

Please help with this C programing

image text in transcribedimage text in transcribedimage text in transcribedThis is staring code:

int main(int argc, char **argv) {

/* Local variables */

float f_array[NUM_TEST_ELEMENTS];

int i_array[NUM_TEST_ELEMENTS], i;

int hist_array[10];

/* Preamble inforamtion */

printf( "CMPSC311 - Assignment #1 - Spring 2020 " );

/* Step #1 - read in the float numbers to process */

for (i=0; i

scanf("%f", &f_array[i]);

}

/* Step #2 - Alter the values of the float array as follows: all

even numbered indices of the array should be multiplied by 0.78

if the value is greater than 50 and 1.04 otherwise. All odd valued

indices should multiplied by 0.92 if the value is greater than 50

and 1.15 otherwise */

????

/* Step #3 Round all of the values to integers and assign them

to i_array using the round311 function */

????

/* Step #4 - Print out all of the floating point numbers in the

array in order on a SINGLE line. Each value should be printed

with 2 digits to the right of the decimal point. */

printf( "Testing printfloatArr311 (floats): " );

printfloatArr311( f_array, NUM_TEST_ELEMENTS );

printf(" ");

/* Step #5 - Print out all of the integer numbers in the array in order on a SINGLE line. */

printf( "Testing printIntArr311 (integers): " );

printIntArr311( i_array, NUM_TEST_ELEMENTS );

printf(" ");

/* Step #6 - sort the integer values, print values */

printf( "Testing bubbleSort311 (integers): " );

bubbleSort311( i_array, NUM_TEST_ELEMENTS );

printIntArr311( i_array, NUM_TEST_ELEMENTS );

printthf(" ");

/* Step #7 - print out e last 5 values of the integer array in binary. */

printf( "Testing toBinary: " );

for (i=NUM_TEST_ELEMENTS-6; i

toBinary( ???? );

}

printf(" ");

/* Declare an array of integers. Fill the array with a count (times three) of the number of values for each

set of tens within the floating point array, i.e. index 0 will contain the count of rounded values in the array 0-9 TIMES THREE, the

second will be 10-19, etc. */

????

histogram311(????);

/* Exit the program successfully */

printf( " CMPSC311 - Assignment #1 - Spring 2020 Complete. " );

return( 0 );

}

this is output:

Testing printfloatArr311 (floats): 47.19, 52.39, 66.18, 11.02, 77.52, 66.37, 4.95, 14.78, 69.11, 57.70, 40.87, 70.82, 69.34, 11.02, 62.02, 59.91, 44.01, 63.59, 3.36, 68.29, 46.23, 83.24, 51.93, 20.91, 53.42, 90.01, 39.17, 61.28, 53.69, 44.27, 43.96, 40.58, 51.74, 86.80, 48.40, 53.88, 37.36, 37.07, 31.89, 40.96, 55.53, 7.74, 49.65, 36.16, 77.87, 22.27, 13.14, 44.09, 75.03, 17.57, 37.19, 46.69, 34.92, 45.14, 70.47, 52.77, 54.22, 46.50, 44.48, 92.28, 55.75, 84.50, 78.62, 21.50, 54.18, 40.84, 40.73, 53.77, 23.73, 37.09, 47.27, 58.17, 38.21, 11.38, 55.67, 31.46, 25.31, 7.72, 17.58, 59.94, 45.31, 38.21, 5.14, 56.58, 23.83, 49.46, 59.91, 73.19, 69.82, 18.03, 48.50, 54.80, 45.02, 50.92, 41.91, 49.94, 62.61, 60.86, 12.20, 17.65

Testing printIntArr311 (integers): 47, 52, 66, 11, 78, 66, 5, 15, 69, 58, 41, 71, 69, 11, 62, 60, 44, 64, 3, 68, 46, 83, 52, 21, 53, 90, 39, 61, 54, 44, 44, 41, 52, 87, 48, 54, 37, 37, 32, 41, 56, 8, 50, 36, 78, 22, 13, 44, 75, 18, 37, 47, 35, 45, 70, 53, 54, 46, 44, 92, 56, 85, 79, 22, 54, 41, 41, 54, 24, 37, 47, 58, 38, 11, 56, 31, 25, 8, 18, 60, 45, 38, 5, 57, 24, 49, 60, 73, 70, 18, 49, 55, 45, 51, 42, 50, 63, 61, 12, 18

Testing bubbleSort311 (integers): 3, 5, 5, 8, 8, 11, 11, 11, 12, 13, 15, 18, 18, 18, 18, 21, 22, 22, 24, 24, 25, 31, 32, 35, 36, 37, 37, 37, 37, 38, 38, 39, 41, 41, 41, 41, 41, 42, 44, 44, 44, 44, 44, 45, 45, 45, 46, 46, 47, 47, 47, 48, 49, 49, 50, 50, 51, 52, 52, 52, 53, 53, 54, 54, 54, 54, 54, 55, 56, 56, 56, 57, 58, 58, 60, 60, 60, 61, 61, 62, 63, 64, 66, 66, 68, 69, 69, 70, 70, 71, 73, 75, 78, 78, 79, 83, 85, 87, 90, 92

Testing toBinary: 0100 1111 0101 0011 0101 0101 0101 0111 0101 1010 0101 1100

+----------------------------------------+ 19 | xx xx | 18 | xx xx | 17 | xx xx | 16 | xx xx | 15 |.................xx..xx.................| 14 | xx xx | 13 | xx xx xx | 12 | xx xx xx | 11 | xx xx xx xx | 10 |.....xx......xx..xx..xx..xx.............| 09 | xx xx xx xx xx | 08 | xx xx xx xx xx xx | 07 | xx xx xx xx xx xx | 06 | xx xx xx xx xx xx xx | 05 |.xx..xx..xx..xx..xx..xx..xx..xx.........| 04 | xx xx xx xx xx xx xx xx | 03 | xx xx xx xx xx xx xx xx xx | 02 | xx xx xx xx xx xx xx xx xx xx | 01 | xx xx xx xx xx xx xx xx xx xx | 00 |.xx..xx..xx..xx..xx..xx..xx..xx..xx..xx.| +----------------------------------------+ 00 10 20 30 40 50 60 70 80 90

3. You are to complete the assign1-cmpsc311-sp20 program. The assign1-cmpsc311-sp20 program receives an array of floating point values, one per line and executes a number of operations and functions. Complete the code in the assign1-cmpsc311-sp20.c per the instructions below. Locations where code or declarations need to be added or completed are indicated by ???). The code should: o Step #1 - Read in the float numbers to process from standard input (this is done for you, so you don't need to add code). Note that there will be exactly NUM_TEST_ELEMENTS elements read. o Step #2 - Alter the values of the float array as follows: all even numbered indices of the array should be multiplied by 0.78 if the value is greater than 50 and 1.04 otherwise. All odd valued indices should multiplied by 0.92 if the value is greater than 50 and 1.15 otherwise. Step #3 - Create a function round311 that rounds a floating point number to the nearest integer, where you round up if the value to the right of the decimal place is 0.5 or higher. Round all of the values of the floating point array to integers (but do not alter the original value in the floating point array) and assign the rounded values to the same index of the i_array using the round311 function. o Step #4 - Create a function printfloatArr311 that prints all of the values of an array, comma separated (with no trailing comma and newline at the end). The function should receive as parameters a pointer to an array of floats and a size of the array (integer). Each value should be printed with exactly 2 digits to the right of the decimal point. Step #5 - Create a function printIntArr311 that prints all of the values of an array, comma separated (with no trailing comma and newline at the end). The function should receive as parameters a pointer to an array of integers and a size of the array (integer). Print out all of the floating point numbers in the array in order on a SINGLE line using the printfloatArr311 function. o Step #6 - Write a bubble sort function bubbleSort311 that receives a pointer to an array o Step #6 - Write a bubble sort function bubbleSort311 that receives a pointer to an array of integers and a size of the array (integer). An example of the algorithm can be found here 2. Pass the integer array i_array into the function and sort it. The function should receive as parameters a pointer to an array of integers and a size of the array (integer). Use printIntArr311 to print out the array as in the previous step. o Step #7 - Create a function toBinary that receives a byte (char) and prints is value out in binary (with spaces every nibble). Print out the first 5 values if i_array using this function. o Step #8 - Create a function countRange311 that receives reference to an array of floating point values, a integer indicating how many elements are in the array and a int minimum and maximum values. The function will return the number of elements (after rounding) between min and max (inclusive). Next, declare an array of 10 integers at the top of the main function. Fill the array with a count (times three) of the number of values for each set of tens within the floating point array, i.e. index O will contain the count of rounded values in the array 0-9 >TIMES THREE, the second will be 10-19, etc. all the way to 90-99. Use the countRange311 to fill the array. o Step #9 - Create a function histogram311 that receives a reference to an array of integer values calculated in the previous step and prints out a histogram showing the counts of the different values. The Y-axis should display count values from 0-19. The function should check the number of elements and return with a -1 value if it is not 10. Otherwise, the function should create a histogram indicating the numbers calculated in Step #6 above. All labels, lines, and framing of the histogram should look like the following (this is exactly what the output for the test input should be, see below). - - - - - - - - + - - - - - - - - +-------- 19 XX XX 18 XX XX 17 | XX XX 16 | XX XX 15 1. XX. .XX.. 141 XX XX 131 XX XX XX 12 xx xx xx 11 | XX XX XX XX 10 1.....XX......XX..XX.XX.XX.. 09 XX XX XX XX XX 08 XX X X XX XX XX XX 07 XX X X XX XX XX XX 06 xx xx xx xx xx xx XX 05 1.xx.xx..XX.XX..XX.XX.XX.XX....... 04 | xx xx xx xx xx xx xx XX 03 | xx xx xx xx xx xx xx xx xx | 02 | xx xx xx xx xx xx xx xx xx xx || 01 | xx xx xx xx xx xx xx xx xx xx | 00 1.xx..XX.. XX. XX. XX. XX. XX. XX. XX. XX. | - + - - - - - - - - - - - - - - - - + 00 10 20 30 40 50 60 70 80 90

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions