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

Program Challenge#1 : Charge Account Validation From thebook: Write a program th

ID: 3617629 • Letter: P

Question

Program Challenge#1: Charge Account Validation From thebook: Write a program that lets the userenter a charge account number. The program should determine if thenumber is valid by checking for it in the following list (orderdoes not matter): 5658845, 8080152, 1005231, 4520125, 4562555,6545231, 7895122, 5552012, 3852085, 8777541, 5050552, 7576651,8451277, 7825877, 7881200, 1302850, 1250255, 4581002 The list ofnumbers above should be initialized in a single dimensional array.A simple linear search should be used to locate the number enteredby the user. If the user enters a number that is in the array, theprogram should display a message saying the number is valid. If theuser enters a number that is not in the array, the program shoulddisplay a message indicating the number is invalid. Additional notes to thebook: Use the following skeleton for themain function:

long accounts[arrSize] = { ... };

int results;

long number;

number = get_number(); // subroutine will ask user for anumber

results = searchList(accounts, arrSize, number); // subroutine willsearch number in array

if (results == -1)

cout << "The number you entered is invalid. ";

else

cout << "The number you entered is valid and found inelement " << results << " in the array." <<endl;

Note: The function searchList is basically alreadygiven to you in program 8-1. Make sure you understand what thefunction returns to 'results' and how the program uses thatinformation.


Write a program that lets the userenter a charge account number. The program should determine if thenumber is valid by checking for it in the following list (orderdoes not matter): 5658845, 8080152, 1005231, 4520125, 4562555,6545231, 7895122, 5552012, 3852085, 8777541, 5050552, 7576651,8451277, 7825877, 7881200, 1302850, 1250255, 4581002 The list ofnumbers above should be initialized in a single dimensional array.A simple linear search should be used to locate the number enteredby the user. If the user enters a number that is in the array, theprogram should display a message saying the number is valid. If theuser enters a number that is not in the array, the program shoulddisplay a message indicating the number is invalid. Use the following skeleton for themain function:

long accounts[arrSize] = { ... };

int results;

long number;

number = get_number(); // subroutine will ask user for anumber

results = searchList(accounts, arrSize, number); // subroutine willsearch number in array

if (results == -1)

cout << "The number you entered is invalid. ";

else

cout << "The number you entered is valid and found inelement " << results << " in the array." <<endl;

Note: The function searchList is basically alreadygiven to you in program 8-1. Make sure you understand what thefunction returns to 'results' and how the program uses thatinformation.


Explanation / Answer

Turbo C++ & Borland C++ Complier Code
#include<iostream.h> #include<conio.h> long get_number(); int searchList(long [], const, long); int main() { clrscr(); const arrSize=18; long accounts[arrSize] ={5658845,8080152,1005231,4520125,4562555,6545231,7895122,5552012,3852085,8777541,5050552,7576651,8451277,7825877,7881200,1302850,1250255,4581002}; int results; long number; cout<<"*******************************************"; cout<<" ****** Veena Bhatt, Online**************"; cout<<" *****************************************"; cout<<" ***Charge Account Validation, ch8,pc1***"; number = get_number(); // subroutine will ask user for anumber results = searchList(accounts, arrSize, number); // subroutine will search number in array if (results == -1) cout << "The number you entered is invalid. "; else cout << "The number you entered is valid and foundat position " <<results<< " in the array." << endl; getch(); return 0; }
int searchList(long *acc,const size, long num) { int flag=-1,v; for(v=0;v<size;v++) { if(acc[v]==num) flag=v; } return flag; }
long get_number() { long num; cout<<" Enter your charge account number : "; cin>>num; return num; }
Dev C++ Version ofCode.
#include<iostream> using namespace std; long get_number(); int searchList(long [], const, long); int main() { const arrSize=18; long accounts[arrSize] ={5658845,8080152,1005231,4520125,4562555,6545231,7895122,5552012,3852085,8777541,5050552,7576651,8451277,7825877,7881200,1302850,1250255,4581002}; int results; long number; cout<<"*******************************************"; cout<<" ****** Veena Bhatt, Online**************"; cout<<" *****************************************"; cout<<" ***Charge Account Validation, ch8,pc1***"; number = get_number(); // subroutine will ask user for anumber results = searchList(accounts, arrSize, number); // subroutine will search number in array if (results == -1) cout << "The number you entered is invalid. "; else cout << "The number you entered is valid and foundat position " <<results<< " in the array." << endl; system("pause"); return 0; }
int searchList(long *acc,const size, long num) { int flag=-1,v; for(v=0;v<size;v++) { if(acc[v]==num) flag=v; } return flag; }
long get_number() { long num; cout<<" Enter your charge account number : "; cin>>num; return num; }

#include<iostream.h> #include<conio.h> long get_number(); int searchList(long [], const, long); int main() { clrscr(); const arrSize=18; long accounts[arrSize] ={5658845,8080152,1005231,4520125,4562555,6545231,7895122,5552012,3852085,8777541,5050552,7576651,8451277,7825877,7881200,1302850,1250255,4581002}; int results; long number; cout<<"*******************************************"; cout<<" ****** Veena Bhatt, Online**************"; cout<<" *****************************************"; cout<<" ***Charge Account Validation, ch8,pc1***"; number = get_number(); // subroutine will ask user for anumber results = searchList(accounts, arrSize, number); // subroutine will search number in array if (results == -1) cout << "The number you entered is invalid. "; else cout << "The number you entered is valid and foundat position " <<results<< " in the array." << endl; getch(); return 0; }
int searchList(long *acc,const size, long num) { int flag=-1,v; for(v=0;v<size;v++) { if(acc[v]==num) flag=v; } return flag; }
long get_number() { long num; cout<<" Enter your charge account number : "; cin>>num; return num; }
Dev C++ Version ofCode.
#include<iostream> using namespace std; long get_number(); int searchList(long [], const, long); int main() { const arrSize=18; long accounts[arrSize] ={5658845,8080152,1005231,4520125,4562555,6545231,7895122,5552012,3852085,8777541,5050552,7576651,8451277,7825877,7881200,1302850,1250255,4581002}; int results; long number; cout<<"*******************************************"; cout<<" ****** Veena Bhatt, Online**************"; cout<<" *****************************************"; cout<<" ***Charge Account Validation, ch8,pc1***"; number = get_number(); // subroutine will ask user for anumber results = searchList(accounts, arrSize, number); // subroutine will search number in array if (results == -1) cout << "The number you entered is invalid. "; else cout << "The number you entered is valid and foundat position " <<results<< " in the array." << endl; system("pause"); return 0; }
int searchList(long *acc,const size, long num) { int flag=-1,v; for(v=0;v<size;v++) { if(acc[v]==num) flag=v; } return flag; }
long get_number() { long num; cout<<" Enter your charge account number : "; cin>>num; return num; }
#include<iostream> using namespace std; long get_number(); int searchList(long [], const, long); int main() { const arrSize=18; long accounts[arrSize] ={5658845,8080152,1005231,4520125,4562555,6545231,7895122,5552012,3852085,8777541,5050552,7576651,8451277,7825877,7881200,1302850,1250255,4581002}; int results; long number; cout<<"*******************************************"; cout<<" ****** Veena Bhatt, Online**************"; cout<<" *****************************************"; cout<<" ***Charge Account Validation, ch8,pc1***"; number = get_number(); // subroutine will ask user for anumber results = searchList(accounts, arrSize, number); // subroutine will search number in array if (results == -1) cout << "The number you entered is invalid. "; else cout << "The number you entered is valid and foundat position " <<results<< " in the array." << endl; system("pause"); return 0; }
int searchList(long *acc,const size, long num) { int flag=-1,v; for(v=0;v<size;v++) { if(acc[v]==num) flag=v; } return flag; }
long get_number() { long num; cout<<" Enter your charge account number : "; cin>>num; return num; }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote