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
|
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void fileInput();
void displayList(const int[], int);
void sortedList(const int[], int);
void displaySortlist(const int[], int);
int searchFile(const int [], int, int);
int main()
{
cout << "Charge Account Validation" << endl;
cout << "created by Cedric Shumate" << endl << endl;
fileInput();
displayList();
void sortedList();
displaySortlist();
searchFile();
cout << "Enter a number in the account or 9999 to quit: ";
int number;
cin >> number;
while (number < 1 || number >9999)
{
cout << "Error: Enter a number that is in the account: ";
cin >> number;
}
system("pause");
return 0;
}
void fileInput()
{
const int ARRAY_SIZE = 20;
int accountNumbers[ARRAY_SIZE];
int count = 0;
ifstream inputFile;
inputFile.open("charges.txt");
while (count < ARRAY_SIZE && inputFile >> accountNumbers[count])
count++;
inputFile.close();
}
void displayList(const int ARRAY_SIZE[], int size)
{
cout << "Original Order" <<endl;
cout << "=========================" <<endl;
for (int count = 0; count < size; count++)
cout << ARRAY_SIZE[count];
cout << endl;
}
void sortedList( int array[], int account)
{
int startSort, minIndex, minNumb;
for (startSort = 0; startSort < (account - 1); startSort++)
{
minIndex = startSort;
minNumb = array[startSort];
for (int index = startSort + 1; index < account; index++)
{
if (array[index] < minNumb)
{
minNumb = array[index];
minIndex = index;
}
}
}
}
void displaySortlist(const int ARRAY_SIZE[], int size)
{
cout << "Sorted List" <<endl;
cout << "*********************" <<endl;
for (int count = 0; count < size; count++)
cout << ARRAY_SIZE[count];
cout << endl;
}
int searchFile ( const int array[], int account, int value)
{
int first = 0,
last = account - 1,
middle,
position = -1;
bool found = false;
while (!found && first <= last)
{
middle = (first + last)/2;
if (array[middle] == value)
{
found = true;
position = middle;
}
else if (array[middle] > value)
last = middle - 1;
else
first = middle + 1;
}
return position;
}
|