Question: stocks.c main file #include #include #include #include io.h #include stats.h #include //strtod #include int main(int argc, char* argv[]) { int size, i; char order; //user

 stocks.c main file #include #include #include #include "io.h" #include "stats.h" #include

stocks.c main file

#include #include #include #include "io.h" #include "stats.h" #include //strtod #include int main(int argc, char* argv[]) { int size, i; char order; //user has enter nothing in command prompt float *array; if(argc

} //user enters a value seperated by ',' //assume the delimeter is a ',' else if(argv[1]=",") { //count the number of entries //allocate the values into array /eed to use a single pointer to allocate the values into array, but how? int i; for (i = 0; i

stats.h

#ifndef STATS_H #define STATS_H void sort (float output[], int size, char order); float get_average(const float array[], int size); float get_variance(const float array[], int size); float get_median(const float array[], int size); int get_max(const float array[], int size); int get_min(const float array[], int size); int get_num_tokens(const char str[], char delim); #endif

stats.c

#include #include "stats.h"

// sorts the values of an array according to order void sort (float output[], const int size, char order) { int i, j; float temp;

if (order == 'a' || order == 'A') { for ( i = 0; i output[j] ) { temp = output[i]; output[i] = output[j]; output[j] = temp; } } else if (order == 'd' || order == 'D') { for ( i = 0; i

}

// calculates the mean of the elements of an array float get_average(const float array[], int size) { int i; float sum = 0.0;

for (i = 0; i

sum /= size;

return sum; }

// calculates the variance of the emelemts of an array // this function calls the get_average to get the mean float get_variance(const float array[], int size) { int i; float sum = 0.0;

float mean = get_average(array, size);

for (i = 0; i

sum = sum/size - mean*mean;

return sum;

}

// gets the median of an array after it sorts it float get_median(const float array[], int size) { int i; float temp_array[size]; // temp array tp be manipulated float median;

// copy oroginal array to the temp array for (i = 0; i

sort(temp_array, size, 'a');

if (size % 2 == 0) median = (temp_array[size/2] + temp_array[size/2-1])/2.0; else median = temp_array[size/2];

return median; }

// finds the maximum value of the elements of an array int get_max(const float array[], int size) { int i; float max = array[0];

for (i = 0; i = max) max = array[i];

return max; }

// finds the minimum value of the elements of an array int get_min(const float array[], int size) { int i; float min = array[0];

for (i = 0; i

return min;

}

io.h

#ifndef IO_H #define IO_H

void read_array(float array[], int size); void print_greeting(void); void print_array(const float array[], int size); void print_results(const float array[], int size, float median, float min, float max, float mean, float variance);

#endif

io.c

#include #include "io.h"

// prompt the user for input and read the values into an array void read_array(float array[], int size) { int i = 0; for (i = 0; i

// say hi to the user void print_greeting(void) { printf("Welcome! Today we are reading and analyzing stocks. "); }

// display array values void print_array(const float array[], int size) { int i = 0;

for (i = 0; i

printf(" ");

}

// print the stat results including input data void print_results(const float array[], int size, float median, float min, float max, float mean, float variance) {

printf(" Say something here about the ouput "); print_array(array, size); printf("median: $%.2f ", median); printf("min: $%.2f ", min); printf("max: $%.2f ", max); printf("variance: $%.2f ", variance); printf("mean: $%.2f ", mean);

}

getting these errors need help fixing them so file can compile and run.

stocks.c:75:26: error: 'array' undeclared here (not in a function) stocks.c:75:33: error: 'size' undeclared here (not in a function) stocks.c:81:1: warning: data definition has no type or storage class [enabled by default] stocks.c:81:1: warning: parameter names (without types) in function declaration [enabled by default] stocks.c:81:1: error: conflicting types for 'print_results' stocks.c:4:0: io.h:7:6: note: previous declaration of 'print_results' was here stocks.c:82:1: error: expected identifier or '(' before 'return' stocks.c:83:1: error: expected identifier or '(' before '}' token

Algorithms Data: Stock prices input in several ways Result: mean, variance, min, max, and median of input data i begin 2 if the user enters nothing on the command line then This is the modified Project 3 greet and read the data; 4 end else if they enter one value then if it's a single number then Implement the mdified Project 3 logic in reading the data; end else assume the delimiter is a: count the number of entries; allocate array parse the input string and store the values into arrays 12 13 14 end end 16 else get the number of entries put each entry into an array 18 19 end 20 end 21 Now you should have the array populate 22 The same as project 3 from this point forward; Algorithm 1: Gather the data from the user then process How to run the code $./stocks .x # conditional online 2 $ ./stocks.x 13 # conditional on line 6 $ ./stocks .x 12.5,11.31 ,12,22.43 , 23.1,31 ,12,11,11.11 # conditional o /stocks . x 12.5 11.31 12 22.43 23.1 31 12 11 11.11 # conditional o

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!