#include <iostream.h>
#include <math.h>
class Statistc
{
//-----------------------------------------------------------------------------------
private:
int array[100];
int count;
//-----------------------------------------------------------------------------------
public:
Statistc(int a[], int n)
{
count=n;
int i;
for( i=0 ; i<count; i++)
{
array[i] = a[i];
}
sortArray();
}
//-----------------------------------------------------------------------------------
void sortArray()
{
int i,j;
for(i=0; i<count; i++)
{
for (j=0; j<count-1; j++)
{
if(array[j]<array[j+1])
{
int temp=array[j+1];
array[j+1]=array[j];
array[j]=temp;
}
}
}
}
//-----------------------------------------------------------------------------------
int getTotal()
{
int total=0;
for(int i=0; i<count; i++)
{
total=total + array[i];
}
return total;
}
//-----------------------------------------------------------------------------------
int getMean()
{
int mean;
mean= (getTotal())/(getCount());
return mean;
}
//-----------------------------------------------------------------------------------
int getDifferenceAndSquare(int num)
{
int dif = (num - getMean());
return dif*dif;
}
//-----------------------------------------------------------------------------------
double getStrdDeviation()
{
int sumOfDifs = 0;
int meanOfDifs;
double sqrtOfMean;
double strdDeviation;
for ( int i=0; i<count; i++)
{
sumOfDifs = sumOfDifs + getDifferenceAndSquare(array[i]);
}
meanOfDifs = sumOfDifs / getCount();
sqrtOfMean = sqrt( meanOfDifs );
strdDeviation = sqrtOfMean;
return strdDeviation;
}
//-----------------------------------------------------------------------------------
int getCount()
{
return count;
}
//------------------------------------------------------------------------------------
int *getMaxAndMin()
{
int maxAndMin[2];
maxAndMin[0] = array[0];
maxAndMin[1] = array[0];
for( int i=0; i<count; i++ )
{
if( array[i] > maxAndMin[0] ) maxAndMin[0] = array[i];
if( array[i]< maxAndMin[1] ) maxAndMin[1] = array[i];
}
int *pointToMaxAndMin = maxAndMin;
return pointToMaxAndMin;
}
//-----------------------------------------------------------------------------------
int getFrequencyOfNumber(int num)
{
int countAppearance = 0;
for(int i=0; i<count; i++)
{
if( array[i] == num )
{
countAppearance++;
}
}
return countAppearance;
}
//-----------------------------------------------------------------------------------
int * getFrequency()
{
int frequency[100];
int * pointToFrequency = frequency;
for(int i=0; i<count; i++)
{
frequency[i] = getFrequencyOfNumber(array[i]);
}
return pointToFrequency;
}
//-----------------------------------------------------------------------------------
int getMode()
{
int mode;
int *ptr = getFrequency();
int max;
max = *ptr;
int index=0;
for ( int i=0; i<count; i++ )
{
if (*(ptr+i) > max)
{
max = *(ptr+i);
index = i;
}
}
mode = array[index];
return mode;
}
//-----------------------------------------------------------------------------------
double getMedian()
{
double median;
if((count%2)==0)
{
median = ( ( array[(count/2)] + array[(count/2 - 1)]) / 2);
}
else
{
median = array[((getCount() + 1) / 2-1)];
}
return median;
}
//-----------------------------------------------------------------------------------
int *getArray()
{
int * ptr = array;
return ptr;
}
}; //end of class Statistc
//-----------------------------------------------------------------------------------
int main()
{
int array[100];
int n;
cout<<"\nEnter how many number do you want to insert\n";
cin>>n;
cout<<"\nInsert"<<n<<" numbers\n";
int i;
for( i=0; i<n; i++)
{
cin>>array[i];
}
Statistc object(array, n);
cout<<"\nTotal : "<<object.getTotal()<<"\n";
cout<<"\nMean : "<<object.getMean()<<"\n";
cout<<"\nStandard Deviation: "<<object.getStrdDeviation()<<"\n";
cout<<"\nCount : "<<object.getCount()<<"\n";
int *ptrToMaxAndMin = object.getMaxAndMin();
cout<<"\nMaximum : "<<*ptrToMaxAndMin<<"\nMinimum : "<<*(ptrToMaxAndMin+1)<<"\n";
int *ptrToFrequency = object.getFrequency();
int j;
cout<<"\nFREQUNCIES of the numbers\n";
for ( j=0; j<n; j++)
{
cout<<"Frequency of"<<array[j]<<" : "<<*(ptrToFrequency+j)<<"\n";
}
cout<<"\nMode : "<<object.getMode()<<"\n";
cout<<"\nMedian : "<<object.getMedian()<<"\n";
cout<<"Enter the largestKth \n";
int * ptr = object.getArray();
int kth;
cin>>kth;
cout<<"\nLargest "<<kth<<" number is\n"<<*(ptr+kth-1)<<"\n";
return 0;
} //end of main
Can anyone explain this program and description to me at least
I need help is necessary to
Or at least help me to describe the function MaxAndMin - Mode - Frequency
You'll have to ask more specific questions (what question?) than that.
Or at least help me to describe the function MaxAndMin - Mode - Frequency
I'm gonna hazard a guess and say the functions calculate the minimum and maximum, mode and frequency of the elements in "array". They're also all broken, since pointers to local arrays are returned.
Can you is be patient with little
I am beginner in programming
I have this program .. I want to write how it was done
What are the laws used in his work
I do not know what the solution
I have this program .. I want to write how it was done
What are the laws used in his work
Which lines don't you understand?
If you were tasked with this, surely you must have had some lessons on C++ before.
If not, now would be a good time to catch up.