#include <cstdlib>
#include <ctime>
#include <iostream>
usingnamespace std;
class SortArray
{
public:
int randomArray[];
int find(int randomArray[], int len, int seek);
void MoveUp();
void OutputNumbers();
void GenerateRandomNumbers();
};
void main(void)
{
SortArray cSort;
srand(time(0));
///Gets ten random numbers from 1 through 100
cSort.GenerateRandomNumbers();
cout<<"The numbers before they are sorted"<<endl;
///Outputs The Numbers Before Sorting Them
cSort.OutputNumbers();
cout<<endl<<endl;
cSort.find();
///Sorts Numbers
cSort.MoveUp();
cout<<"The numbers after they have been sorted"<<endl;
///Outputs Number After They Have Been Sorted
cSort.OutputNumbers();
cout<<endl;
system("pause");
}
void SortArray::MoveUp()
{
int placeHolder;
for(int g=1; g<51; g++)
{
///Since I am comparing array positions next to eachother I initialize the variable numberAbove to one higher than g
for(int numberAbove=g+1; numberAbove<51; numberAbove++)
{
///If the number lower in array position is higher in value than number higher in array position...proceed to switch
if(randomArray[g] > randomArray[numberAbove])
{
///Puts Lesser Value Into A Placeholder
placeHolder = randomArray[numberAbove];
///Puts Bigger Value In Upper Position
randomArray[numberAbove] = randomArray[g];
///Puts Lesser Value in Lower Position
randomArray[g] = placeHolder;
}
}
}
}
void SortArray::GenerateRandomNumbers()
{
for(int i=1; i<51; i++)
{
randomArray[i] = (rand() % (100 - 60 + 1)) + 60;
}
}
void SortArray::OutputNumbers()
{
for(int j=1; j<51; j++)
{
cout<<randomArray[j]<<endl;
}
}
int SortArray::find(int randomArray[], int len, int seek)
{
for (int i = 0; i < 50; ++i)
{
if (randomArray[i] == 80)
return i;
}
return -1;
}