206k views
2 votes
In this module you learned about searching, sorting and algorithms in C++ and how to implement these elements in your C++ programs. In this assignment you will implement your knowledge of searching, sorting and algorithms for charge account validation system. Write a program that lets the user enter a charge account number. Be sure to include comments throughout your code where appropriate. The program should determine if the number is valid by checking for it in the following list of valid account numbers:

814942053331743080098675596395269814449539938719751047262931356428263717502196086650316483824195904578589971890467499412545408Initialize a one-dimensional array with these values. Then use a simple linear search to locate the number entered by the user. If the user enters a number that is in the array, the program should display a message indicating that the account number is valid. If the user enters a number not in the array, the program should display a message indicating it is invalid.Next, using the same one-dimensional array, use a bubble-sort to put the array in order and perform a binary search to locate the number entered by the user. If the user enters a number that is in the array, the program should display a message indicating that the account number is valid. If the user enters a number not in the array, the program should display a message indicating it is invalid.

User Udan
by
5.8k points

1 Answer

2 votes

Question is not well presented:

The search strings in the question are not well formatted.

First thing, I'll arrange the account number in order of 7;

Meaning that the length of each account number is 7

8149420 5333174 3080098 6755963 9526981 4449539 9387197 5104726 2931356 4282637 1750219 6086650 3164838 2419590 4578589 9718904 674994 12545408

Answer:

// This program is written in C++ Programming Language

// Comments are used for explanatory purpose

// Program starts here

#include <iostream>

using namespace std;

// Initialise Function

int ArrayList(int[], int, int);

// Main Method starts at

int main()

{

// The list of account is 18; so, we Initialise an integer Variable to hold this value

const int acctlist = 18;

// Initialise an array to hold the account numbers

int List[acctlist] = { 8149420 5333174 3080098 6755963 9526981 4449539 9387197 5104726 2931356 4282637 1750219 6086650 3164838 2419590 4578589 9718904 674994 12545408

};

// Declare account number and search result Variables of type integer

int accountnumber, Result;

// Prompt user for account number

cout << "Enter a valid account number: ";

cin >> accountnumber;

// Determine if valid or not

Result = ArrayList(List, acctlist, accountnumber);

if(Result == -1){

cout << "Account number " << AcctNum << " is invalid.\\";}

else{

cout << "Account number " << List[Result] << " is valid\\";

}

return 0;

}

// Function starts here

int ArrayList(int list[], int size, int value)

{

int index = 0,

pos = -1;

bool seen = false;

// Check if Account number is seen in list

while (!seen && index < size)

{

if (list[index] == value)

{

seen = true;

}

pos = index;

}

index++;

}

return pos;

}

User DanielCollier
by
5.3k points