Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is for c programming: I am having the following errors in my code. I have included the pseudo code provided by my professor as

This is for c programming: I am having the following errors in my code. I have included the pseudo code provided by my professor as well as the main, calculations , and io. Please assist with my errors. Leave comments where you made any changes.

Thank you.

Errors:

stocks.c: 70:4: error expected expressin before 'float'

float * parseString(char str [])

stocks.c: 118:30: error: 'array' undeclared here(not in a function)

float mean = get_average(array, size)

stocks.c: 118:37: error: 'size' undeclared here(not in a functin)

float mean = get_average(array, size);

stocks.c: 125:5: error: conflicting types for 'print_results'

In file included from stocks.c: 17: 0:

io.h:18:6: note: previous declaration of 'print_results' was here

void print_results(const float array[], int size, float median, float min,

float max, float mean, float variance);

stocks.c:127:5: error: expected identifier or '(' before 'return'

return 0;

stocks.c:129:1: error: expected identfier or '(' before '}' token

This is my main:

* stocks.c

* program 4 is a program that will

*inputs data on the command line to process stock values

Here is my main:

*

* gcc -o stocks.x stocks.c

* ./stocks.x

*

*/

#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

if(argc

{

//from Proj 3 greet and read data

// greet and get the stock values

print_greeting();

printf("How many stocks prices would you like to analyze? ");

scanf("%d", &size);

// read the data

float array[size];

read_array(array, size);

}

//user has enter only one argument

else if(argc=1)

{

//user enters one value

//check whether the argument is numeric

if(isdigit(argv[0]))

{

proj3(); //calls the function proj3

}

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

for (int i = 0; i

//parse the input string and store the value into arrays

float * parseString(char str[])

{

float result[10];//declaring result array, using max size for size

char *token = NULL;//intializing token to split

int count=0;

char *unconverted;

for(token = strtok(str,","); token != NULL; token = strtok(NULL, ","))

{

//strtok splits string according to the delimeter which is ,

result[count]=strtod(token, &unconverted);//adding to the result array, strtod, converts the token char* to float

count++;

}

return result;//returning result

}

{

size[i]=argv[i];

}

}

}

//user enters the number of entries

else

// get the number of entries

{

//allocate the values into array

for (int i = 0; i

{

}

}

}

// same as from project 3

//get the stats

float mean = get_average(array, size);

float variance = get_variance(array, size);

float min = get_min(array, size);

float max = get_max(array, size);

float median = get_median(array, size);

// show the results

print_results(array, size, median, min, max, mean, variance);

return 0;

}

These are my stat.c:

* This stats.c file includes the functions for * average, variance, max, min, and median. * */

#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;

}

This is my io.c:

* this is the io.c file * * */

#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);

}

Here is the pseudo code:

image text in transcribed

image text in transcribed

Algorithms Data: Stock prices input on several lines, one long string or values separated by spaces Result: mean, variance, min, max, median, sorting of input data begin 2if the user enters nothing on the command line then give a description of the project; ask them to enter the stocks one one line separated by a comma & hit enter when done 5 end 6else if they enter one value then if it's a single number then Implement Project 3 logic in reading the data; end 10 end 11 else 12 13 14 15 end 16 else assume the delimiter is a ','; count the number of entries & allocate arrays; parse the input string and store the values into arrays

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

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

Question What happens to my plan if I die?

Answered: 1 week ago

Question

Briefly explain the various types of leadership ?

Answered: 1 week ago

Question

Explain the need for and importance of co-ordination?

Answered: 1 week ago

Question

Explain the contribution of Peter F. Drucker to Management .

Answered: 1 week ago

Question

What is meant by organisational theory ?

Answered: 1 week ago