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 =...
Im trying to create a function in C where it takes an array and size and...
Im trying to create a function in C where it takes an array and size and returns the largest absolute value in the array (either negative or positive) using only stdio.h. Any help would be greatly appreciated! Ex: if the array is { -2.5, -10.1, 5.2, 7.0}, it should return -10.1 Ex: if the array is {5.1, 2.3, 4.9, 1.0}, it should return 5.1. double getMaxAbsolute(double array[], int size) {     double max = array[0];    double abs[size];    for...
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)
IN C++ Create a single function. and pass in a integer which is the the planet...
IN C++ Create a single function. and pass in a integer which is the the planet number. 1 will be Mercury and 9 will be Pluto, etc. Return via reference the planet name, planet weight ( or mass ) in kg, and the distance from the sun in km. Please create a nice looking table with headings and show the 9 planets. Here is an example of the first 4 planets in the table. You will need to add in...
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...
Making a blackjack game in javascript Create a function called createDeck() that will create an array...
Making a blackjack game in javascript Create a function called createDeck() that will create an array of objects (52). Each object contains two properties: suit and value. The suit property will be either 'Hearts', 'Clubs', 'Diamonds', or 'Spades'. The value property will be either 'Ace', 'King', 'Queen', 'Jack', 'Ten', 'Nine', 'Eight', 'Seven', 'Six', 'Five', 'Four', 'Three' , or 'Two''. Note: We will probably want to store possible suits and values in separate arrays. Create a function called shuffleDeck() that will...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT