Menu

[Solved] Following Sample Program Gets Data User Enters Data Integer Array Function Getdataintoarra Q37173740

The following sample program gets data from the user, and then enters those data into an integer array. The function getDataIC:Usersandrew sourcereposintArray Debug intarray Please enter a number between 0 and 100 (or -1 to quit) 90 X: 90 copyinYour revised program should generate screen output as shown in Figure 6.2. C:Usersandrew sourcerepos intArray Debug>intar

Need help, Thanks in advance. ( Its in C language)

The following sample program gets data from the user, and then enters those data into an integer array. The function getDataIntoArray() returns the number of items successfully entered into the array Sample screen of running the program is shown in Figure 6.1 8.1. #defineCRTSECURENOWARNINGS #include <stdio.h> #define SIZE 100 void initializeArray(int[SIZE]); nitialize each element to be zero int getDatalntoArray(int[SIZE]D; I/This function takes as a parameter an array of strings void showDataFromArray(int[SIZE], int); //show all the elements in a given array void findMax (int[SIZE], int); //find the largest number in the given array double average(int[SIZE], int); //return the average of all numbers in the given array —- void mainO { int intArray[SIZE]; initializeArray(intArray); int number – getDatalntoArray(intArray); printf(“number: %dn”, number); printf(nCalling the showDataFromArray0 function …n”); showDataFromArray(intArray, number); //Display all the names currently in that array printf(nCalling the findMax) function …n”); findMax(intArray, number); printf(nCalling the average) function …n”) printf(“The average of all entered numbers is %2f.ln”, average(int Array, number); void initializeArray(int arr[SIZE]) for (int i-0;i< SIZE; i++) arri0; int getDatalntoArray(int arr[SIZE]) int num -0; int index 0: 0 printf(” Please enter a number between 0 and 100 (or -1 to quit): “); scanf(“%d” , &num); printf(“x: %din”, num); if (num !=-1) { printf(“copying data into array …In”); arr[index] = num; index++ } while (index < SIZE && num !=-1); if (index >0) printf(“InYou have successfully entered %d items.nln”, index); else printf(“No item was entered.n”); return index; C:Usersandrew sourcereposintArray Debug intarray Please enter a number between 0 and 100 (or -1 to quit) 90 X: 90 copying data into array Please enter a number between 0 and 100 (or -1 to quit) 80 X: 80 copying data into array Please enter a number between 0 and 100 (or -1 to quit) 50 X: 50 copying data into array Please enter a number between 0 and 100 (or -1 to quit 99 X: 99 copying data into array Please enter a number between 0 and 100 (or -1 to quit): 100 X: 100 copying data into array Please enter a number between 0 and 100 (or -1 to quit): -1 You have successfully entered 5 items number 5 Figure 6.1 Sample output of getting user data into an array 8.2. Design and implement functions that process the array intArray created in the sample program, including showDataFromArray(), findMax(), and average(). Sample calls to those functions are shown as comments in the sample program. The function showDataFromArray() takes the intArray and the number of elements as parameters, and shows each of the elements currently in the array (along with its respective index value in that array) The function findMax() searches through the intArray to find the largest number currently in that array. The function average() calculates and returns the average of all numbers currently in that array Implement the showDataFromArray() and the findMax() functions. When ready, uncomment the respective sample calls in the main() function, and then run the revised program Your revised program should generate screen output as shown in Figure 6.2. Your revised program should generate screen output as shown in Figure 6.2. C:Usersandrew sourcerepos intArray Debug>intarray Please enter a number between 0 and 100 (or -1 to quit 90 X: 90 copying data into array Please enter a number between 0 and 100 (or -1 to quit): 80 X: 80 copying data into array Please enter a number between 0 and 100 (or -1 to quit): 50 X: 50 copying data into array Please enter a number between 0 and 100 (or -1 to quit): 99 X: 99 copying data into array .. Please enter a number between 0 and 100 (or -1 to quit) 100 X: 100 copying data into array Please enter a number between 0 and 100 (or -1 to quit): -1 X: -1 You have successfully entered 5 items. number 5 Calling the showDataFromArray() function item[0]:90 item[1]: 80 item[2]: 50 item[3]: 99 item[41: 100 Calling the findMax() function max value: 100 … Calling the average() function The average of all entered numbers is 83.80 C:Users andrew sourcerepos intArray Debug>_ Show transcribed image text The following sample program gets data from the user, and then enters those data into an integer array. The function getDataIntoArray() returns the number of items successfully entered into the array Sample screen of running the program is shown in Figure 6.1 8.1. #defineCRTSECURENOWARNINGS #include #define SIZE 100 void initializeArray(int[SIZE]); nitialize each element to be zero int getDatalntoArray(int[SIZE]D; I/This function takes as a parameter an array of strings void showDataFromArray(int[SIZE], int); //show all the elements in a given array void findMax (int[SIZE], int); //find the largest number in the given array double average(int[SIZE], int); //return the average of all numbers in the given array —- void mainO { int intArray[SIZE]; initializeArray(intArray); int number – getDatalntoArray(intArray); printf(“number: %dn”, number); printf(nCalling the showDataFromArray0 function …n”); showDataFromArray(intArray, number); //Display all the names currently in that array printf(nCalling the findMax) function …n”); findMax(intArray, number); printf(nCalling the average) function …n”) printf(“The average of all entered numbers is %2f.ln”, average(int Array, number); void initializeArray(int arr[SIZE]) for (int i-0;iintarray Please enter a number between 0 and 100 (or -1 to quit 90 X: 90 copying data into array Please enter a number between 0 and 100 (or -1 to quit): 80 X: 80 copying data into array Please enter a number between 0 and 100 (or -1 to quit): 50 X: 50 copying data into array Please enter a number between 0 and 100 (or -1 to quit): 99 X: 99 copying data into array .. Please enter a number between 0 and 100 (or -1 to quit) 100 X: 100 copying data into array Please enter a number between 0 and 100 (or -1 to quit): -1 X: -1 You have successfully entered 5 items. number 5 Calling the showDataFromArray() function item[0]:90 item[1]: 80 item[2]: 50 item[3]: 99 item[41: 100 Calling the findMax() function max value: 100 … Calling the average() function The average of all entered numbers is 83.80 C:Users andrew sourcerepos intArray Debug>_

Expert Answer


Answer to The following sample program gets data from the user, and then enters those data into an integer array. The function get… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *