Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using the following account numbers write a program with appropriate functions t

ID: 3680357 • Letter: U

Question

Using the following account numbers write a program with appropriate functions that lets a user charge a valid account number. this program simply validates the entered charge number. So using a vector, read in the account numbers from a file (the above linked valid_accounts.txt), ask the user for their account number, then search the vector to determine if the account is valid. If the account is valid, display to the screen a message indicating the number is valid, if not display a message saying it is invalid. Use the selection sort method to sort the array Use the binary search method to find the account. Sample output

Explanation / Answer

#include <iostream>

using namespace std;

bool searchList(long [], int, long);
const int SIZE = 18;
long chargeAccount,
results;
int main()
{

long tests[SIZE] = {5658845, 450125, 7895122, 8777541, 8451277,1302850,

8080152, 4562555, 5552012, 5050552, 7825877, 1250255,1005231, 654231,

3852085, 7576651, 7881200, 4581002};

results;
cout << "Enter your Charge Account Number: " << endl;
cin >> chargeAccount;

results = searchList (tests, SIZE, results);
if (results == -1)

cout << "You Entered a Valid Number. ";

else
{
cout << "You Entered an Invalid Number. ";
cout << (results + 1) << ". ";

}

return 0;

}


bool searchList(long list[], int numElems, long value)
{

int index = 0;

int position = -1;   

bool found = false;


while (index < numElems && !found)

{

if (list[index] == value)

{

found = true;   

position = index;

}

index++;   

}

return position;
}