Using the following account numbers write a program with appropriate functions t
ID: 3678144 • 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
enter your account number: 5658845 ccount: 5658845 validExplanation / Answer
#include <iostream>
using namespace std;
bool searchList(long [], int, long);
long chargeAccount;
const int ARRAY_SIZE = 18;
int main()
{
long tests[ARRAY_SIZE] = {5658845, 4520125, 7895122, 8777541, 8451277,1302850,
8080152, 4562555, 5552012, 5050552, 7825877, 1250255,1005231, 6545231,
3852085, 7576651, 7881200, 4581002};
int results;
cout << "Enter your Charge Account Number: " << endl;
cin >> chargeAccount;
results = searchList (tests, ARRAY_SIZE, chargeAccount);
if (results == -1)
cout << "Your Charge Account is Valid. ";
else
{
cout << "Your Charge Account is Invalid. ";
}
return 0;
}
bool searchList(long list[], int numElems, long value)
{
for (long i = 0; i = numElems;i++)
if (list [i] == value)
return true;
return false;
}
while (index < numElems && !found)
{
if (list[index] == value)
{
found = true;
position = index;
}
index++;
}
return found;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.