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
|
#include <iostream>
using namespace std;
void inputNum(int& count, int array[]);
void fillArray(int a[], int size, int& num);
void sort(int a[], int num);
void swapValues(int& num1, int& num2);
void countNum(int array1[], int& i, int& numCount, int size);
int main()
{
int arrays[25], size = 0, numCount;
inputNum(size, arrays);
sort(arrays, size);
cout << "\nNumbers:\tAmount:\n";
for (int i = 0; i < size; i++)
{
countNum(arrays, i, numCount, size);
cout << arrays[i] << "\t\t" << numCount << endl;
}
system("pause>nul");
}
void inputNum(int& count, int array[])
{
int i = 0, input;
cout << "This program sorts numbers from highest to lowest and counts how many there are of each. \n \nPlease enter 25 numbers or enter 100 to stop earlier: \n \n";
cin >> input;
while (input != 100 && i < 25)
{
array[i] = input;
i++;
cin >> input;
}
count = i;
}
void sort(int a[], int num)
{
for (int index = 0; index < num - 1; index++)
{
for (int index2 = index + 1; index2 < num - 1; index2++)
{
if (a[index] < a[index2])
swapValues(a[index], a[index2]);
}
}
}
void swapValues(int& num1, int& num2)
{
int temp = num1;
num1 = num2;
num2 = temp;
}
void countNum(int a[], int& i, int& numCount, int size)
{
int index = i + 1;
numCount = 1;
for (index; index < size; index++)
{
if (a[i] == a[index])
{
numCount++;
i++;
}
else return;
}
}
|