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
|
#include <iostream>
#include <fstream>
using namespace std;
const int SIZE = 50;
void input(int a[], int size);
void sort(int num[], int& count);
//int Count(int num[], int& count);
int main()
{
ifstream fin;
int num[SIZE], count = 0, i=0, numUsed=0, nums = -1337;
char ans, file_name[16];
cout << "This Program will read in an array of numbers and outputs from largest to smallest and its occurence!\n";
cout << "\nDo You want to provide the integers provided to the program? (Type 'Y' or 'y')\n";
cin >> ans;
if(ans =='Y' || ans == 'y')
{
input(num, SIZE);
}
else
{
cout << "You Chose input integers from a file!\n";
cout << "Please Enter the name of the Input File?(Maximun of 15 characters)ex. test.txt\n";
cin >> file_name;
fin.open(file_name);
if(fin.fail())
{
cout << "Input File Opening Failed.\n";
system("PAUSE");
exit(1);
}
while (fin >> nums)
{
num[i] = nums;
i++;
numUsed ++;
}
sort(num, numUsed);
fin.clear();
fin.close();
system("PAUSE");
return 0;
}}
void input(int num[], int size)
{
int count=0, k=0;
cout << "You Chose to Provide integers provided to the program!\n";
cout << "Enter up to 50 whole number integers, Enter -1337 to End! \n";
while(count < 50)
{
cin >> num[k];
if(num[k] == -1337)
break;
k++;
count ++;
}
sort(num, count);
}
void sort(int num[], int& count)
{
//cout << " Using Sort!";
for(int i =0; i <= count-1; i++)
{
for(int j = i+1; j <= count-1; j++)
{
int temp;
if(num[i] < num[j])
{
temp = num[i];
num[i] = num[j];
num[j] = temp;
}
}
}
int number, occurence =0, count2 = 0, i;
cout << "N\tCount\n";
for(i=0; i<=count-1; i++)
{
//number = num[i];
for(int j=0; j<= count-1; j++)
{
if(num[i] == num[j])
{
count2++;
occurence = j;
}
}
if(num[i] == -1337)
{
}
else
{
cout << endl << num[i] << "\t" << count2;
i= occurence;
count2 = 0;
}
}
cout << endl;
system("PAUSE");
}
|