Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is the code: stats.c: #include #include #include stats.h //TODO: fix the error in this function void readInArray(int *arr, int size) { int i; printf(Enter

image text in transcribed

This is the code:

stats.c:

#include

#include

#include "stats.h"

//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

//

scanf("%d", &arr[i]);

}

return;

}

int * generateRandomArray(int size) {

int * randomArr = malloc(sizeof(int) * size);

for(int i=0; i

randomArr[i] = rand();

}

return randomArr;

}

void printArray(const int *arr, int size) {

printf("[");

for(int i=0; i

printf("%d, ", arr[i]);

}

printf("%d ] ", arr[size-1]);

}

//change the getMean function to get parameters as array and size,CHEGGEA

double getMean( const int *arr,int size )

//double getMean( , ) {

{

double sum=0;

int i;

for(i = 0; i

{

sum+=arr[i];

}

return sum/size;

}

//change the getMean function to get parameters as array and size,CHEGGEA

int getMin( const int *arr,int size )

//int getMin( , ) {

{

int i;

int min=arr[0];

for(i = 0; i

{

if(min > arr[i])

min=arr[i];

}

return min;

}

//change the getMean function to get parameters as array and size,CHEGGEA

int getMax(const int *arr ,int size )

//int getMax( , )

{

int i;

int max=arr[0];

for(i = 0; i

{

if(max

max=arr[i];

}

return max;

}

===================

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.

*/

void readInArray(int *arr, int size);

/**

* Generates a random array of integers of the given

* size. This function assumes that the random number

* generator has already been seeded.

*/

int * generateRandomArray(int size);

/**

* Prints the given array to the standard output

*/

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

/*

* TODO:

* 1. Write prototypes for each of these functions

* 2. Write documentation for each of these functions

* 3. Implement the functions in stats.c

*/

//added parameters to the following functions

double getMean( const int *arr,int size );

int getMin( const int *arr,int size );

int getMax(const int *arr ,int size );

================

This what was given for statsMain.c:

/** * Statistics main driver program */ #include #include

#include "stats.h"

#define SIZE 500

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

//seed the random number generator with the current time 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; }

What should I do for statsMain.c

3.1 Static Arrays Navigate back to the statistics directory. Several files have been provided for you. The stats.c and stats.h file define several utility functions to manipulate arrays and to compute statistics on those arrays. The statsMain.c file contains a main driver program. Recall that you will compile these files using: gcc -c stats. gcc -o runstats stats. o statsMalnc In this activity, you will implement and use several functions that use arrays as parame- ters. 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 2. 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 3. In the statsMain.c declare a static array that is "large enough" as indicated by the other clues in the code. Use your declared static array as an argument to readInArray and the other function calls. 4. Run your program and demonstrate it to a lab instructor

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_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Genetic Databases

Authors: Martin J. Bishop

1st Edition

ISBN: 0121016250, 978-0121016258

More Books

Students also viewed these Databases questions

Question

1. Explain how business strategy affects HR strategy.

Answered: 1 week ago