Question: I am trying to find interquartile range in C++ in a function I created called intQuartRangeFunc(). Can someone please show me how to take values
I am trying to find interquartile range in C++ in a function I created called intQuartRangeFunc(). Can someone please show me how to take values from an array and display the range from my function. Here is my code so far.
#include
// Function declarations and definitions
/* Function of given size and populated with random values between 0 - 100 */ void myFunc(int* array, const unsigned int size){ srand(time(nullptr)); cout << "["; for(int i = 0; i < size; ++i) { array[i] = rand() % 100; cout << " " << array[i]; } cout << " ]" << endl; delete [] array; }
/* Function to calculate the average of the array should take as arguments the array and its size */
void avgFunc(int* array, const unsigned int size){ double sum = 0; double avg = 0; int* myArray = array;
for(int i = 0; i < size; ++i){ sum += myArray[i]; } avg = sum / size;
cout << fixed << setprecision(2) << "The average is: " << avg << endl; delete [] myArray; }
// Function to calculate median should take as arguments the array and it size
void medianFunc(int* array, const unsigned int size){ int* myArray = array; double median = 0; int middle = 0;
middle = size / 2;
if(size % 2 == 0) { median = (myArray[middle] + myArray[middle - 1]) / 2; cout << "The median is: " << median << endl; } else { median = myArray[middle]; cout << "The median is: " << median << endl; } delete [] myArray; }
//Function calculates standard deviation of the array
void stdDevFunc(int* array, const unsigned int size){ double sum = 0; double avg = 0; double stdDevSqr = 0; double stdDev = 0; int* myArray = array;
for(int i = 0; i < size; ++i){ sum += myArray[i]; } avg = sum / size;
for(int i = 0; i < size; ++i){ stdDevSqr += pow(myArray[i] - avg, 2); } stdDev = sqrt(stdDevSqr / size); cout << "The standard deviation is: " << stdDev << endl; delete [] myArray; }
// Function calculates interquartile range of the array
void intQuartRangeFunc(int* array, const unsigned int size){
}
int main() {
int* myArray; unsigned int mySize;
cout << "Enter array size: "; cin >> mySize; int* theSize = new int[mySize];
myFunc(myArray, mySize); avgFunc(myArray, mySize); medianFunc(myArray, mySize); stdDevFunc(myArray, mySize); intQuartRangeFunc(myArray, mySize);
delete[] myArray;
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
