Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

stocks.c #include #includestats.h #define MAXIMUM_SIZE 100 void main() { int data[MAXIMUM_SIZE]; int output[MAXIMUM_SIZE]; int size; char choice ,choice1; int i, j, temp; float average ,median,max,min,variance;

stocks.c

#include #include"stats.h" #define MAXIMUM_SIZE 100 void main() {

int data[MAXIMUM_SIZE]; int output[MAXIMUM_SIZE]; int size; char choice ,choice1; int i, j, temp; float average ,median,max,min,variance;

printf("Do you want to enter the number of stocks: Y/N "); //taking input for character choice = getchar( ); switch ( choice ) { case Y: printf("Enter number of stocks: "); scanf("%d", &size); /* Input elements in array */ printf("Please Enter Price for the Stocks: "); for(i=0; i

} break; case N: /* Input elements in array */ printf("Please Enter Price for the Stocks: "); for(i=0; i

} break; }

printf("", );

}

Stats.h

float get_average(const float data[], const int size){ float average= 0.0; float sum = 0.0; int i=0; for (i ; i < size ; i++) { sum = sum + data[i]; } average = sum / size; return average;

}

float get_variance(const float data[], const int size){

float average= 0.0; float sum = 0.0; float sum_one= 0.0; float variance = 0.0; float temp = 0.0; int i=0; for (i; i < size ; i++) { sum = sum + data[i]; } average = sum / size; for (i; i < size ; i++) { temp = data[i] - average; sum_one = sum_one + temp * temp; } variance = sum_one / (float)size; return variance;

}

float get_max(const float data[], const int size){

int i=0; int position = 0; float max_value = data[0];

for (i ; i < size; i++) { if (data[i] > max_value) { max_value = data[i]; position = i+1; } } return data[position];

}

float get_min(const float data[], const int size){

int i=0; int position = 0; float min_value = data[0];

for (i ; i < size; i++) { if (data[i] < min_value) { min_value = data[i]; position = i+1; } } return data[position];

} float get_median(const float input[], const int size){ float median,temp = 0.0; int i,j=0;

// Sorting the array - Ascending Order for (i ; i < size; ++i) { for (j = i + 1; j < size; ++j) { if (input[i] > input[j]) { temp = input[i]; input[i] = input[j]; input[j] = temp; } } }

if( size % 2 == 0){ median = (input[size/2] + input[size/2+1])/2.0 ; } else{ median = input[size/2 + 1]; }

return median; }

void sort(const float input[], float output[], const int size, const char order){

float temp = 0.0; int i,j=0;

// Sorting the array - Ascending Order if(order == 'a'){ for (i ; i < size; ++i) { for (j = i + 1; j < size; ++j) { if (input[i] > input[j]) { temp = input[i]; input[i] = input[j]; input[j] = temp; output[j] =temp; } } } }

// Sorting the array - Decending Order if(order == 'a'){ for (i ; i < size; ++i) { for (j = i + 1; j < size; ++j) { if (input[i] < input[j]) { temp = input[i]; input[i] = input[j]; input[j] = temp; output[j] =temp; } } } } return output[]; }

something in my array is giving me a few errors

stats.h:89:1: error: assignment of read-only location '*(input + (sizetype)((unsigned int)i * 4u))' stats.h:90:1: error: assignment of read-only location '*(input + (sizetype)((unsigned int)j * 4u))' D:\Users\bdn4\AppData\Roaming\Microsoft\Windows\Recent\stats.h: In function 'sort': stats.h:121:1: error: assignment of read-only location '*(input + (sizetype)((unsigned int)i * 4u))' stats.h:122:1: error: assignment of read-only location '*(input + (sizetype)((unsigned int)j * 4u))' stats.h:138:1: error: assignment of read-only location '*(input + (sizetype)((unsigned int)i * 4u))' stats.h:139:1: error: assignment of read-only location '*(input + (sizetype)((unsigned int)j * 4u))' stats.h:145:15: error: expected expression before ']' tokenstats.h:145:1: warning: 'return' with a value, in function returning void [enabled by default] how do I go about fixing them to make the code to work.

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

Recommended Textbook for

Students also viewed these Databases questions

Question

What is the difference between a current and non-current liability?

Answered: 1 week ago

Question

Understand how customers respond to effective service recovery.

Answered: 1 week ago