// Andres Guzman CSC5 Chapter 8, P. 487, #1
/******************************************************************************
*
* DETERMINE NUMBER VALIDATION
* ____________________________________________________________________________
* This program will determine whether the inputed numbers in the account match
* those of the valid numbers.
*
* Computation:
*
* Uses a linear search in the linear function to compare the values in the
* subscripts to the inputed values of the user. If equal, returns a valid
* status, and a negative status otherwise.
* ____________________________________________________________________________
*
* INPUT
* account = The valid numbers
* accountnum = Holds the inputed value for account numbers
*
* OUTPUT
* array = Displays the status of the inputed numbers
*
******************************************************************************/
#include <iostream>
using namespace std;
int linear(const int a[], int b, int c); //Function Prototype
const int SIZE = 18;
int main()
{
//
//Initialization List
int account[SIZE] = {5658845, 4520125, 7895122, 8777541, 8451277, 1302850,
8080152, 4562555, 5552012, 5050552, 7825877, 1250255,
1005231, 6545231, 3852085, 7576651, 7881200, 4581002};
int accountnum; //Holds Input Value for users account numbers
int array; //Holds the results of the numbers
//
//Prompt Input Display
cout << "Please enter a Number: ";
cin >> accountnum;
//
//Input Validation
while(accountnum < 0)
{
cout << "Cannot Be Negatives. Please Try Again." << endl;
cout << "Please enter a Number: ";
cin >> accountnum;
}
//
//Adds Function Results to Variable Status
array = linear(account, SIZE, accountnum);
//
//Determines whether the inputed values are equal to the subscript
if(array == -1)
cout << "\nInvalid." << endl;
else
cout << "\nValid" << endl;
return 0;
}
/*******************************************************************************
* Adding Definition to the function. This function will search through the list
* of values in the array subscript and determine whether the value inside
* matches the inputed value of the user, in which case will then determine the
* status of the input numbers by using a linear search.
******************************************************************************/
int linear(const int a[], int b, int c)
{
int index = 0;
int position = -1;
bool found = false;
while (index < b && !found)
{
if(a[index] == c)
{
found = true;
position = index;
}
index++;
}
return position;
}
Ly8gQW5kcmVzIEd1em1hbiBDU0M1IENoYXB0ZXIgOCwgUC4gNDg3LCAjMQogLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKgogKgogKiAgREVURVJNSU5FIE5VTUJFUiBWQUxJREFUSU9OCiAqICBfX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCiAqICBUaGlzIHByb2dyYW0gd2lsbCBkZXRlcm1pbmUgd2hldGhlciB0aGUgaW5wdXRlZCBudW1iZXJzIGluIHRoZSBhY2NvdW50IG1hdGNoCiAqICB0aG9zZSBvZiB0aGUgdmFsaWQgbnVtYmVycy4KICoKICogIENvbXB1dGF0aW9uOgogKgogKiAgVXNlcyBhIGxpbmVhciBzZWFyY2ggaW4gdGhlIGxpbmVhciBmdW5jdGlvbiB0byBjb21wYXJlIHRoZSB2YWx1ZXMgaW4gdGhlCiAqICBzdWJzY3JpcHRzIHRvIHRoZSBpbnB1dGVkIHZhbHVlcyBvZiB0aGUgdXNlci4gSWYgZXF1YWwsIHJldHVybnMgYSB2YWxpZAogKiAgc3RhdHVzLCBhbmQgYSBuZWdhdGl2ZSBzdGF0dXMgb3RoZXJ3aXNlLgogKiAgX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fXwogKgogKiAgSU5QVVQKICogIGFjY291bnQgPSBUaGUgdmFsaWQgbnVtYmVycwogKiAgYWNjb3VudG51bSA9IEhvbGRzIHRoZSBpbnB1dGVkIHZhbHVlIGZvciBhY2NvdW50IG51bWJlcnMKICoKICogIE9VVFBVVAogKglhcnJheSA9IERpc3BsYXlzIHRoZSBzdGF0dXMgb2YgdGhlIGlucHV0ZWQgbnVtYmVycwogKgogKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqLwojaW5jbHVkZSA8aW9zdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbGluZWFyKGNvbnN0IGludCBhW10sIGludCBiLCBpbnQgYyk7CQkvL0Z1bmN0aW9uIFByb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