//This the one that requires a binary search of the data. Your program should read the //charge account numbers from a file and the contents of the file should be unsorted. The //charge accounts are found the problem entitled Charge Account Validation.
//The file will have one charge account number on each line of the file. You will need to //create your own data file. The file should be named: chargeaccounts.dat
// Chapter 8, programming Challenge 4
//Account Validation Modification
//Godwin Armah-Afful
#include<iostream>
#include<iomanip>
#include <fstream>
using namespace std;
const int ARRAY_SIZE = 18; // the Array size
int chargeAcct[ARRAY_SIZE]; // Array with 18 elements
int count = 0; // Loop counter variable
ifstream inputFile; // Input File stream oblject
inputFile.open("chargeaccount.dat"); //Open data File
//Read the numbers from the files into the Array
// After this loop executes, the counter variable will hold
// the number of values that were stored in the array
while(count < ARRAY_SIZE&&inputFile >> chargeAcct[count])
count++;
//close File
inputFile.close();
// Display the numbers read
cout <<"The numbers are:";
for (int index=0; index < count; index++)
cout <<chargeAcct[index] << " ";
cout << endl;
system("pause");
return 0;
}
int accountNumber; // to hold the account number
// sort the list of arrays
selectionSort( accountNumber,SIZE);
// Search the array by the number and indicate it is valid or Invalid
found = searchList( , SIZE, accountNumber);
if (found) {
cout << "You Entered a Valid Number" << endl;
}
else
{
( found == -1);
cout << "Your Charge Account is Invalid.\n";
}
system("pause");
return 0;
}
bool binarysearch(long list[], int numElems, long value)
{
long index = 0;
int position = -1;
bool found = false;
while (index < numElems && !found)
{
if (list[index] == value)
{
found = true;
position = index;
}
index++;
}
system("pause");
return found;
}
// I have been able to solve the data file problem but it the rest of the code is full of errors and I am just a beginner