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
|
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
void arrSelectSort(int [], int);
void rowsOfTen(int [], int);
void displayAscend(int [], int);
int main()
{
int *pointer = nullptr;
srand(time(nullptr));
int numbOfTests = rand() % (200 - 1 + 1) + 1;
pointer = new int[numbOfTests];
for(int i = 0; i < numbOfTests; i++)
{
pointer[i] = rand() % (99 - 55 + 1) + 55;
}
cout << "Ascending Order\n";
cout << string(30,'-') << endl;
arrSelectSort(pointer, numbOfTests);
displayAscend(pointer, numbOfTests);
cout << endl << endl;;
cout << "Rows Of Ten\n";
cout << string(30,'-') << endl;
rowsOfTen(pointer, numbOfTests);
delete [] pointer;
return 0;
}
void arrSelectSort(int arr[], int size)
{
int startScan, minIndex;
int minElem;
for(startScan = 0; startScan < (size - 1); startScan++)
{
minIndex = startScan;
minElem = arr[startScan];
for(int index = startScan + 1; index < size; index++)
{
if((arr[index]) < minElem)
{
minElem = arr[index];
minIndex = index;
}
}
arr[minIndex] = arr[startScan];
arr[startScan] = minElem;
}
}
void displayAscend(int array[], int size)
{
for(int i = 0; i < size; i++)
{
cout << array[i] << " ";
}
}
// Print a histogram
void rowsOfTen(int array[], int size)
{
// First, get the min and max values
int minVal = array[0];
int maxVal = array[size-1];
// Now get the width of each row. We'll print 8 rows.
int width = (maxVal-minVal) / 8; // width of each bar
// Initialize the high mark for the current row.
// We initialize it to a low value so the first row
// gets printed properly.
int high = minVal;
// Now go through the values and print '*' characters until we
// hit the high mark. At that point we'll start a new row.
//we'll move on to the next row
for (int i=0; i<size; ++i) {
if (array[i] >= high) {
// This value is the start of a new row. Print the legend for it.
cout << '\n';
cout << high << '-' << (high+width-1) << ": ";
// And now increment the high mark
high += width;
}
// Print a '*' for this value
cout << '*';
}
}
|