Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that inputs data on the command line stock.x runs normal program

ID: 3598322 • Letter: W

Question

Write a program that
inputs data on the command line

stock.x runs normal program

stock.x 13 is on command line

stock.x 13 26 13 is on command line but with spaces

stock.x 13, 26, 13, 40 is on command line but with commas

how do I implement this in the code and it knows how to decipher is user inputs commas or spaces or 1 number or execute regular program also still do the calculations mean median min max etc.

need to add to code below.

io.h:

void sort(const float input[], float output[], const int size,
const char order);
void read_data(float array[], int size);
void print_results(const float array[], int size, float mean,
float median, float min, float max, float variance);
void print_greeting();

io.c:

#include <stdio.h>
#include "io.h"




void read_data(float array[], int size)
{
int i = 0;
printf("Please enter the stocks you wish to analyze: ");
for(i = 0; i < size; i++)
{
printf("Please enter the stock price #%d: ", i + 1);
scanf("%f", &array[i]);
}
}


void print_results(const float array[], int size, float mean,
float median, float min, float max, float variance)
{
printf("Mean = $%.2f ", mean);
printf("Median = $%.2f ", median);
printf("Min = $%.2f ", min);
printf("Max = $%.2f ", max);
printf("Variance = $%.2f ", variance);
}


void print_greeting()
{
printf(" This application will compute the statistics of and sort ");
printf("a series of stock prices. ");
}

stats.h:

float get_average(const float data[], const int size);
float get_variance(const float data[], const int size);
float get_max(const float data[], const int size);
float get_min(const float data[], const int size);
void sort(const float input[], float output[], const int size,
const char order);
float get_median(const float input[], const int size);
void read_data(float array[], int size);
//void print_results(const float array[], int size, float mean, float
//median, float min, float max, float variance);
void print_greeting();

stats.c:

#include <float.h>
#include <limits.h>
#include "stats.h"


void sort(const float input[], float output[], const int size, const char order)
{
int i = 0,
j = 0;

float temp;
for(i = 0; i < size; i++)
output[i] = input[i];
for(i = 0; i < size - 2; i++)
{
for(j = i + 1; j <= size - 1; j++)
{
if(order == 'A')
{
if (output[i] > output[j])
{
temp = output[i];
output[i] = output[j];
output[j] = temp;
}
}
else if(order == 'D')
{
if(output[i] < output[j])
{
temp = output[i];
output[i] = output[j];
output[j] = temp;
}
}
}
}
}

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

float get_max(const float data[], const int size)
{
    float max = data[0];
    for(int i = 1; i < size; i++)
        if(data[i] > max)
            max = data[i];
    return max;      
}
float get_min(const float data[], const int size)
{
    float min = data[0];
    for(int i = 0; i < size; i++)
        if(data[i] < min)
            min = data[i];
    return min;      
}
float get_median(const float input[], const int size)
{
    float output[size];
    sort(input, output, size, 'a');
    if(size % 2 == 0)
        return (output[size/2] + output[size/2+1]) / 2;
    else
        return output[size/2];  
}
float get_variance(const float data[], const int size)
{
    double mean = get_average(data, size);
    double variance = 0;
    for(int i = 0; i < size; i++)
        variance += (data[i] - mean) * (data[i] - mean);
    variance /= size;
    return variance;  
}

And stocks.c:

#include <stdio.h>
#include <float.h>
#include <limits.h>
#include "io.c"
#include "stats.c"


int main()
{
int size = 0;
float median = 0.0f,
variance = 0.0f,
max = 0.0f,
min = 0.0f,
average = 0.0f;
  
float array[size],
data[size],
input[size];

  
char order;
  
//print greeting
print_greeting();


//ask user number of stocks being analyzed
printf("Enter the number of stocks we will be analyzing: ");
scanf("%d", &size);
//read data one at a time
read_data(data, size);
//Ask user if they want to sort their prices
printf("Do you want to sort the prices in ascending, ");
printf("or descending order? (A/D). ");
scanf(" %c", &order);
//get the stats
average = get_average(data, size);
median = get_median(data, size);
variance = get_variance(data, size);
max = get_max(data, size);
min = get_min(data, size);
//print the results
print_results(data, size, average, median, min, max, variance);
return 0;
}

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

Explanation / Answer

#include <stdio.h>
#include "io.h"




void read_data(float array[], int size)
{
int i = 0;
printf("Please enter the stocks you wish to analyze: ");
for(i = 0; i < size; i++)
{
printf("Please enter the stock price #%d: ", i + 1);
scanf("%f", &array[i]);
}
}


void print_results(const float array[], int size, float mean,
float median, float min, float max, float variance)
{
printf("Mean = $%.2f ", mean);
printf("Median = $%.2f ", median);
printf("Min = $%.2f ", min);
printf("Max = $%.2f ", max);
printf("Variance = $%.2f ", variance);
}


void print_greeting()
{
printf(" This application will compute the statistics of and sort ");
printf("a series of stock prices. ");
}

stats.h:

float get_average(const float data[], const int size);
float get_variance(const float data[], const int size);
float get_max(const float data[], const int size);
float get_min(const float data[], const int size);
void sort(const float input[], float output[], const int size,
const char order);
float get_median(const float input[], const int size);
void read_data(float array[], int size);
//void print_results(const float array[], int size, float mean, float
//median, float min, float max, float variance);
void print_greeting();

stats.c:

#include <float.h>
#include <limits.h>
#include "stats.h"


void sort(const float input[], float output[], const int size, const char order)
{
int i = 0,
j = 0;

float temp;
for(i = 0; i < size; i++)
output[i] = input[i];
for(i = 0; i < size - 2; i++)
{
for(j = i + 1; j <= size - 1; j++)
{
if(order == 'A')
{
if (output[i] > output[j])
{
temp = output[i];
output[i] = output[j];
output[j] = temp;
}
}
else if(order == 'D')
{
if(output[i] < output[j])
{
temp = output[i];
output[i] = output[j];
output[j] = temp;
}
}
}
}
}

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

float get_max(const float data[], const int size)
{
    float max = data[0];
    for(int i = 1; i < size; i++)
        if(data[i] > max)
            max = data[i];
    return max;      
}
float get_min(const float data[], const int size)
{
    float min = data[0];
    for(int i = 0; i < size; i++)
        if(data[i] < min)
            min = data[i];
    return min;      
}
float get_median(const float input[], const int size)
{
    float output[size];
    sort(input, output, size, 'a');
    if(size % 2 == 0)
        return (output[size/2] + output[size/2+1]) / 2;
    else
        return output[size/2];  
}
float get_variance(const float data[], const int size)
{
    double mean = get_average(data, size);
    double variance = 0;
    for(int i = 0; i < size; i++)
        variance += (data[i] - mean) * (data[i] - mean);
    variance /= size;
    return variance;  
}

And stocks.c:

#include <stdio.h>
#include <float.h>
#include <limits.h>
#include "io.c"
#include "stats.c"


int main()
{
int size = 0;
float median = 0.0f,
variance = 0.0f,
max = 0.0f,
min = 0.0f,
average = 0.0f;
  
float array[size],
data[size],
input[size];

  
char order;
  
//print greeting
print_greeting();


//ask user number of stocks being analyzed
printf("Enter the number of stocks we will be analyzing: ");
scanf("%d", &size);
//read data one at a time
read_data(data, size);
//Ask user if they want to sort their prices
printf("Do you want to sort the prices in ascending, ");
printf("or descending order? (A/D). ");
scanf(" %c", &order);
//get the stats
average = get_average(data, size);
median = get_median(data, size);
variance = get_variance(data, size);
max = get_max(data, size);
min = get_min(data, size);
//print the results
print_results(data, size, average, median, min, max, variance);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote