Hey guys
I am trying to calculate statistics for an array
such as min,max,median... etc
and am not getting any answers or results although the program runs well.
here's the full code so far...
//Mostafa Abdel Moez 111606
//Calculating some common statistics for an array of integers.
#include <iostream>
using namespace std;
const int arrSize = 10;
int arr[arrSize];
int arrMin(int , int)
{
int min=arr[0];
for(int i=1;i<arrSize;i++)
{
if(min>arr[i])
{
min=arr[i];
}
return min;
}
}
int arrMax(int, int)
{
int max=arr[0];
for(int i=1;i<arrSize;i++)
{
if(max<arr[i])
{
max=arr[i];
}
return max;
}
}
double arrMean(int, int)
{
double sum = 0;
double avr = 0;
for (int i = 0; i < arrSize; i++)
{
sum+=arr[i];
avr = sum/arrSize;
}
return avr;
}
void bubbleSort(int , int)
{
int i, j, temp;
for ( i = 0; i < arrSize; i++ ) // controls passes through the list
{
for ( j = 0; j < arrSize - 1; j++ ) // performs adjacent comparisons
{
if ( arr[ j ] > arr[ j+1 ] ) // determines if a swap should occur
{
temp = arr[ j ]; // swap is performed
arr[ j ] = arr[ j + 1 ];
arr[ j+1 ] = temp;
}
}
}
}
double arrMedian(int, int)
{
int middle;
double medavr;
double medavrB;
middle = arrSize / 2;
if ( middle % 2)
{
medavr = ((arr[middle]) + (arr[middle + 1])) / 2;
return medavr;
}
else
{
medavrB = arr[middle + (1/2)];
return medavrB;
}
}
int arrMode(int, int)
{
int count[arrSize];
int mode=0;
for (int i=0; i<arrSize; i++)
{
if (count[i] > mode)
mode = arr[i];
}
}
int main()
{
cout<<"Mostafa Abdel Moez 111606\n\n";
cout<<" Calculating some common statistics for an array of integers.\n\n";
arr[arrSize]=(1,2,3,4,5,6,7,8,9,10);
cout<<"Array Min "<<endl;
arrMin(arr[arrSize], arrSize);
cout<<"Array Max "<<endl;
arrMax(arr[arrSize], arrSize);
cout<<"Array Mean "<<endl;
arrMean(arr[arrSize], arrSize);
bubbleSort (arr[arrSize], arrSize);
cout<<"Array Median "<<endl;
arrMedian(arr[arrSize], arrSize);
cout<<"Array Mode "<<endl;
arrMode(arr[arrSize], arrSize);
system("PAUSE");
return 0;
}
.