Question

In: Computer Science

I'm trying to create a function determines the range of outliers in an array using pass...

I'm trying to create a function determines the range of outliers in an array using pass by reference.

I need to write a function that outputs the +3 and -3 standard deviation. I'm having a hard time figuring out what I should identify as my pointers and how to use the pass by reference. This is what I have so far:

#include <stdio.h>

#define ARRAY_SIZE 20

double homeworkArray[ARRAY_SIZE] = { 1.3, 5.7, 2.1, -1.2, 0.5, 4.3, 2.1, 50.2, 3.4, 1.1,

-2.1, 4.1, 6.7, 3.9, 4.1, -0.5, -3.3, 2.1, 5.1, -3.1 };

double CalculateMean(double data[], int size)

{

int i;

double sum = 0.0;

for (i = 0; i < size; i++)

{

sum += data[i];

}

return sum / size;

}

double CalculateStandardDeviation(double data[], int size)

{

double mean = CalculateMean(data, size);

double variance = 0.0;

double diff;

int i;

for (i = 0; i < size; i++)

{

diff = data[i] - mean;

variance += diff * diff;

}

return sqrt(variance / (size));}

}

  

int main(int argc, const char * argv[]) {

double lowerRange=0.0, upperRange=0.0;

  

  

double mean = CalculateMean(homeworkArray, ARRAY_SIZE);

double stddev = CalculateStandardDeviation(homeworkArray, ARRAY_SIZE);

printf("Anything outside of (%.2lf - %.2lf) is an outlier.\n",lowerRange,upperRange);

  

return 0;

}

  

Solutions

Expert Solution

Note: Could you plz go this code and let me know if u need any changes in this.Thank You
_________________

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#define ARRAY_SIZE 20

double homeworkArray[ARRAY_SIZE] = { 1.3, 5.7, 2.1, -1.2, 0.5, 4.3, 2.1, 50.2, 3.4, 1.1,

-2.1, 4.1, 6.7, 3.9, 4.1, -0.5, -3.3, 2.1, 5.1, -3.1 };

double CalculateMean(double data[], int size)

{

int i;

double sum = 0.0;

for (i = 0; i < size; i++)

{

sum += data[i];

}

return sum / size;

}

double CalculateStandardDeviation(double data[], int size)

{

double mean = CalculateMean(data, size);

double variance = 0.0;

double diff;

int i;

for (i = 0; i < size; i++)

{

diff = data[i] - mean;

variance += diff * diff;

}

return sqrt(variance / (size));

}

  
void findOutliers(double* outliers,int *cnt,double lowerRange,double upperRange);
int main(int argc, const char * argv[]) {

double lowerRange=-3, upperRange=3;

  

  

double mean = CalculateMean(homeworkArray, ARRAY_SIZE);

double stddev = CalculateStandardDeviation(homeworkArray, ARRAY_SIZE);

printf("Anything outside of (%.2lf - %.2lf) is an outlier.\n",lowerRange,upperRange);

/* Creating an float array dynamically
* based on the size entered by the user
*/
double* outliers = (double*)malloc(ARRAY_SIZE * sizeof(double));
  
int cnt=0;
  
int i;
findOutliers(outliers,&cnt,lowerRange,upperRange);
for(i=0;i<cnt;i++)
   {
       printf("%.1lf ",outliers[i]);
   }
   printf("\n");
return 0;

}

void findOutliers(double* outliers,int *cnt,double lowerRange,double upperRange)
{
   int i,n=0;
   for( i=0;i<ARRAY_SIZE;i++)
   {
       if(homeworkArray[i]<lowerRange || homeworkArray[i]>upperRange)
       {
           outliers[n]=homeworkArray[i];
           n++;
       }
      
   }
   *cnt=n;
}

______________________

Output:

____________Thank You


Related Solutions

Javascript array of objects: I'm trying to get the input into an array of objects, and...
Javascript array of objects: I'm trying to get the input into an array of objects, and then display the information in a table using a for loop, but I don't think my path is right <!DOCTYPE html> <head> <title>Form</title> <meta charset="utf-8" /> <style media="screen"> h1 { text-align: center; } div { background-color: #pink; border: 2px solid green; padding: 15px; margin: 65px; } </style> <script> var list = []; total = 0; text = ""; function Product(item, quantity, costs){ this.item =...
Array & Function - Can I pass a single parameter to a function that takes two...
Array & Function - Can I pass a single parameter to a function that takes two arguments: data passed from: arrayOne(4); to function: string function (array[], int)
(5)When you pass an array to a function, the function receives Group of answer choices a...
(5)When you pass an array to a function, the function receives Group of answer choices a copy of the array a reference to the array the data type of the array and the number of elements it contains the data type of the array and a pointer to its first element (6)Which of the following statements is not true about a built-in array? Group of answer choices Elements that aren’t initialized will be assigned default values. Its elements must have...
WITH using methods create an array with numbers
IN JAVA  Prompt 3:WITH using methods create an array with numbersint [] number = { 35, 68, 80, 34, 45, 79, 80};Display the numbers in the array using for loopDisplay the sumFind biggest element in the arrayDisplay the numers in the array with index numbersDisplay the numers using for loop in ascending order (sort)
array • First, create a function called addNumber, which has a formal parameter for an array...
array • First, create a function called addNumber, which has a formal parameter for an array of integers and increase the value of each array element by a random integer number between 1 to 10. o Add any other formal parameters that are needed. • Second, create another function called printReverse that prints this array in reverse order. • Then, you need to write a C++ program to test the use of these two functions.
Using an array and a function, print the values of an array backwards. Please follow these...
Using an array and a function, print the values of an array backwards. Please follow these guidelines: - Setup your array manually (whichever values you want, as many as you want and whichever datatype you prefer). - Call your function. You should send two parameters to such function: the array’s length and the array. - Inside the function, go ahead and print the array backwards. - Your function shouldn’t return anything.
I'm trying to create a javascript order form that outputs the items/cost/quantity in the form of...
I'm trying to create a javascript order form that outputs the items/cost/quantity in the form of a table. I have to use a for loop to accomplish this, but I'm not sure where to place the loop & what it needs to reference <!DOCTYPE html> <head> <meta charset="utf-8" /> <style media="screen"> div{ background-color: #f7df3e; border: 1px solid black; padding: 10px; margin: 30px; } h1{ text-align: center; } </style> <script type="text/javascript"> var items = []; var quans = []; var costs...
Write, specify and prove the function copy that copies a range of values into another array,...
Write, specify and prove the function copy that copies a range of values into another array, starting from the first cell of the array. First consider (and specify) that the two ranges are entirely separated. Note: Prototype is as below. void copy(int const* src, int* dst, size_t len){ }
(C++) Hey, so I'm trying to make a Remove() and Add() function for a Binary Search...
(C++) Hey, so I'm trying to make a Remove() and Add() function for a Binary Search Tree (NOT USING RECURSION), can you help? For 3 cases: no child, 1 child and 2 children also for Remove(). This is the function to find the node to be deleted/added TreeNode* PrivateFind(const T& tWhat)    {        //Start from head        TreeNode* tWalk = mHead;        while (tWalk != nullptr)        {            //If found then return...
In C Programing Create a stack using an array. Define the index variable of the array...
In C Programing Create a stack using an array. Define the index variable of the array name to be stacktop. Initially set stacktop to -1. Next create two functions push and pop. Both take as input 3 items: a pointer to the stack in memory, stacktop, and maxstack. Make sure to inc stacktop by one and also remember that stacktop[0] is the bottom of the stack and by stack rule cannot be accessed until all the other items are popped....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT