1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
#include <iostream>
using namespace std;
//Function PRtotypes
void mean(int *,int);
void median(int *, int);
float *mode(int *, int);
void sortAry(int *, int);
void minPos(int *,int ,int);
void swap(int *, int*);
void prntSrt(int *, int);
//Execution begins here
int main()
{
//Declare variables
const int arraySize = 2;
const int patternSize = 10;
//Create the allocated array
int *array=new int[arraySize];
//Creates the array
for(int i=0;i<arraySize;i++){
array[i]=i%patternSize;
}
//outputs the array
for(int i=0; i<arraySize; i++)
{
cout << (*array+i) << " ";
}
prntSrt(array, arraySize);
cout << "The mean of the array is: " << endl;
// CAlls for the mean function
mean(array, arraySize);
delete[] array;
system("PAUSE");
return 0;
}
//Determine the mean
void mean(int *array, int arraySize)
{
float sum=0;
float mea=0;
for(int i=0; i<arraySize; i++){
sum += *(array+i);
mea = sum/arraySize;
}
cout << mea;
}
void sortAry(int *array,int n){
for(int i=0;i<n-1;i++){
minPos(array,n,i);
}
}
void minPos(int *array,int n,int pos){
for(int i=pos+1;i<n;i++){
if(*(array+pos)>*(array+i))
swap(array+pos,array+i);
}
}
void swap(int *a,int *b)
{
//Swap in place
*a=*a^*b;
*b=*a^*b;
*a=*a^*b;
}
void prntSort(int *array, int arraySize)
{
for(int i=0; i<arraySize; i++)
{
cout << *(array+i);
}
}
|