statsc include include include statsh This function prompt

///stats.c//

#include
#include

#include \"stats.h\"

/**
* This function prompts and reads in a collection of numbers
* from the standard input and populates the given array. The
* provided array must be properly initialized for this function
* to work.
*
* //TODO: fix the error in this function
*/
void readInArray(int *arr, int size) {
int i;
printf(\"Enter your list of numbers: \");
for (i = 0; i < size; i++) {
scanf(\"%d\", arr[i]);
}
return;
}

/**
* Creates an array of the given size and populates it
* with random integers between 0 and 99. This function
* assumes that the standard library\'s random number
* generator has already been seeded.
*/
int * createRandomArray(int size) {
int i;
int *arr = NULL;
arr = (int *) malloc(sizeof(int) * size);
for(i=0; i arr[i] = rand() % 100;
}
return arr;
}

/**
* Prints the given array to the standard output in a
* nicely formatted, readable manner.
*/
void printArray(const int *arr, int size) {
int i;
printf(\"[\");
for(i=0; i    printf(\"%d, \", arr[i]);
}
if(size > 0) {
   printf(\"%d\", arr[size-1]);
}
printf(\"]\ \");
}

/**
* TODO: this function computes the mean (average) of
* the numbers contained in the given array
*/
double getMean( , ) {

}

/**
* TODO: this function finds and returns the minimum element
* of the numbers contained in the given array
*/
int getMin( , ) {

___________

//stats.h//

void readInArray(int *arr, int size);
int * createRandomArray(int size);
void printArray(const int *arr, int size);

//TODO: provide the prototypes for each of these functions
double getMean( , );
int getMin( , );
int getMax( , );

______________

//statsMain.c//

/**
* Statistics main driver program
* Arrays & Dynamic Memory Lab
* CSCE 155E
*/
#include
#include

#include \"stats.h\"

#define MAX_SIZE 100

int main(void) {
  
//pay no attention to the man behind the curtain
   srand(time(NULL));
  
int min, max, size;
double mean;
  
printf(\"Enter the amount of numbers you\'d like to find the stats for: \");
scanf(\"%d\", &size);
  
   if(size > MAX_SIZE) {
   printf(\"ERROR: program does not support that many integers!\");
   exit(1);
   }
  
   //TODO: declare a static array \"large enough\" to hold as many integers as we\'ll need

   //TODO (Activity 3): change your delcaration and initialization to use
   // a dynamic array and malloc instead
  
   //TODO: pass the appropriate variable
   readInArray(, size);
  
   //TODO: pass the appropriate variables to your functions here
   min = getMin( , );
max = getMax( , );
mean = getMean( , );
   printArray( , );
  
printf(\"Min: %d\ \", min);
printf(\"Max: %d\ \", max);
printf(\"Mean: %.2f\ \", mean);

return 0;
}

In this activity, you will implement and use several functions that use arrays as parameters. When passed as a parameter to a function, the function also needs to be told how large the array is; typically an integer size variable is passed with any array parameter. You will also declare and populate a static array to test your functions Instructions 1. A function, readInArray has been provided for you that takes an array and its size and prompts the user to enter values to populate the array. However, there is an error in the function: examine the scanf call and determine what is wrong and fix it before proceeding. Using the other functions as a reference, implement the getMin, getMax, and getMean functions. You will need to provide the correct function signature in both the header file and source file In the statsMain.c declare a static array that is \"large enough\" as indicated by the other clues in the code. Use your decared static array as an argument to readInArray and the other function calls Run your program and demonstrate it to a lab instructor. 2. 3. 4. Activity 4: Dynamic Arrays In this activity you will modify the code in statsMain.c to use a dynamic array instead of a static array Instructions 1. Alter your static array declaration to be an integer pointer and add code that calls malloc to initialize the appropriate amount of memory Alter any other code as necessary to remove the \"large enough\" restriction that we had in the previous activity 2. 3. Run your program again and demonstrate it to lab instructor Lab Handout: Arrays & Dynamic Memory Follow Up Demonstrate your program using a \"large\" array. Obviously prompting for and entering a lot of numbers is tedious. So instead, alter your code again to instead take advantage of the createRandomArray function provided for you. Demonstrate it to a lab instructor and have them sign your lab worksheet.

Solution

void readInArray(int* arr, int size)

{
int i;
printf(\"Enter your list of numbers: \");
for (i = 0; i < size; i++) {
scanf(\"%d\", arr[i]);
}
return;
}

void readInArray(int* arr, int size) ;

now check code once

///stats.c// #include #include #include \
///stats.c// #include #include #include \
///stats.c// #include #include #include \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site