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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129

#include <iostream>
#include <ctime> //ctime was used for NULL and Time.
void read_array(int[], int);
void mode(int[],int);
void print_array(int[], int);
int main ()
{
int first[SIZE];
}
void read_array (int read[] , int size1)
{
// This will prevent the outcome number to be the same.
srand (static_cast<unsigned int>(time (NULL)));
for (int index = 0; index < size1; index++)
{
// This will create 30 random numbers.
read[index] = ((rand()30) + 1);
}
/* **************************************************
* After the random excute all the information that *
* the random number obtain it will be passing *
* to the mode and print_array. *
****************************************************/
mode(read, size1);
print_array(read, size1);
}
void mode(int mode[],int size2)
{
/*****************************************
* The following block is use to find out*
* mode how many modes there are. *
*****************************************/
int y[30]={0};//Sets all arrays equal to 0
int count,max=0,no_mode=0,mode_count=0;
int num;
for(int k=0; k<size2; k++)//Loop to cout an array from left to right
{
count=0;
num=mode[k];//Num will equal the value of array x[k]
// Visual Studio show me mode is pointer????
//Nested loop to search for a value equal to x[k]
for(int i=k; i<size2; i++)
{
if(num==mode[i])
//if a number is found that is equal to x[k] count will go up by one
count++;
}
// The array y[k] is initialized the value of whatever count
// is after the nested loop
y[k]=count;
//If count is greater or equal to two then there must be
//at least one mode, so no_mode goes up by one
if(count>=2)
{
no_mode++;
}
}
//after the for loops have excuted and still no_mode hasn't
//been incremented,there mustn't be a mode
if(no_mode==0)
{
cout<<"This data set has no modes\n"<<endl;
return;
}
for(int j=0; j<size2; j++)
//A loop to find the highest number in the array
{
if(y[j]>max)
max=y[j];
}
//This loop finds how many modes there are in the data set
for(int m=0; m<size2; m++)
{
//If the max is equal to y[m] then that is a mode
//and mode_count is incremeted by one
if(max==y[m])
mode_count++;
}
//Prints out how many modes there are
cout<<"This data set has "<<mode_count<<" mode(s)"<<endl;
cout << endl;
for(int m=0; m<size2; m++)
{
//If max is equal to y[m] then the same
//sub set of array x[] is the actual mode
if(max==y[m])
{
cout<<"The value "<<mode[m]<<" appeared "<<y[m]
<<" times in the data set\n"<<endl;
}
}
}
void print_array(int print[], int size3)
{
for (int i= 0; i < size3; i++)
{
// The will prints out number in 10 per lines
cout<<print[i]<<(((i+1)%10==0)? "\n":"\t\t");
}
}
 