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

You will develop a program in C++ to ensure that unauthorized users cannot get i

ID: 3730084 • Letter: Y

Question

You will develop a program in C++ to ensure that unauthorized users cannot get into the system. Your program will check whether the user's entered access code is found in the prerecorded data file. A data file with 300 access codes is provided in the attachment to this assignment. Your program will read this access code data file and search for a match. Only if a match is found, your program will grant the user access. You will accomplish this by creating a sequential search algorithm.

WHEN THE PROGRAM RUNS
Begin by displaying a text heading with the following text banner 48 characters wide:

===== ENTER YOUR CODE TO ACCESS THE SYSTEM =====

The program will ask the user to enter an access code with the prompt:

ATTEMPT n/3: ENTER 4-DIGIT CODE:

The exact text and format are illustrated in the screen shots. Follow the screen shots when creating your user interface.

The program attempts to match the user's input with a valid access code from the data file. The user will be given three attempts to match a valid access code.

Based on the search result, the program will give one of the three possible output messages:

NO MATCH! TRY AGAIN

will display if there is no match with any numbers from the file of valid access codes, and the user has not exhausted all three attempts. The prompt will be repeated. Follow the format given in the screen shots.

If the user's input is validated by a match with a valid access code, this message will display:

================================================

ACCESS GRANTED
WELCOME

================================================

The program stops here. Note that this message is 48 characters wide, the same width as the opening banner.

If the user's input key is not validated by a match with a valid access code by the third attempt, this message will display:

================================================

ACCESS DENIED
GOODBYE

The program stops here. Note that this message is also 48 characters wide, the same width as the opening banner. See screen shots for more details about message formatting and placement.

REQUIREMENTS:

1. USER INTERFACE as shown in the screenshots.
2. FUNCTION: You must develop a sequential search function and name this

function as mySequentialSearch() The input parameters for the mySequentialSearch() function are:

-1-D array (which you will use to store all the data from the access code file)

-The user's search key

-The size of the array

The list of access codes from the data file "SystemAccessCodes.txt" are:

.

Explanation / Answer

/*

Sequential search: is a search when you iterate through all the elements of the array and compare key with each element

and check if key is equal or not.

You can use fstream to do file operations in C++;

Sample Output 1:

===== ENTER YOUR CODE TO ACCESS THE SYSTEM =====

ATTEMPT 1/3 ENTER 4-DIGIT CODE:1234

NO MATCH! TRY AGAIN

ATTEMPT 2/3 ENTER 4-DIGIT CODE:8975

NO MATCH! TRY AGAIN

ATTEMPT 3/3 ENTER 4-DIGIT CODE:1234

================================================

ACCESS DENIED

GOODBYE

================================================

Sample Output 2:

===== ENTER YOUR CODE TO ACCESS THE SYSTEM =====

ATTEMPT 1/3 ENTER 4-DIGIT CODE:1234

NO MATCH! TRY AGAIN

ATTEMPT 2/3 ENTER 4-DIGIT CODE:2018

================================================

ACCESS GRANTED

WELCOME

================================================

*/

//Please create SystemAccessCodes.txt in the same directory where your .cpp file is stored and copy all the codes in that

//Create a .cpp file and copy code from below line to the end of answer

#include<iostream>

#include<fstream>

using namespace std;

//method to search key in array

bool mySequentialSearch(int accessCodes[],int key,int size)

{

for(int i=0;i<size;i++)

{

//If key matches in the array

if(accessCodes[i]==key)

{

return true;

}

}

//if key not found in the array

return false;

}

int main()

{

//Declaring array to store all access code

int accessCodes[300];

//Creating file pointer

ifstream myfile;

//Opening file connection

myfile.open("SystemAccessCodes.txt");

//Reading file and entering all access codes to the array

int size=0;

int num;

while (myfile.eof() == 0)

{

//Reading from file

myfile>>num;

//Adding num to the file

accessCodes[size++]=num;

}

//Closing file connection

myfile.close();

int attempts=3,code;

cout<<"===== ENTER YOUR CODE TO ACCESS THE SYSTEM ====="<<endl;

while(attempts>0)

{

cout<<"ATTEMPT "<<(4-attempts)<<"/"<<3<<" ENTER 4-DIGIT CODE:";

cin>>code;

//Calling method to match code

bool response= mySequentialSearch(accessCodes,code,size);

if(response==true)

{

cout<<"================================================"<<endl;

cout<<"ACCESS GRANTED"<<endl;

cout<<"WELCOME"<<endl;

cout<<"================================================"<<endl;

break;

}

else if(attempts>1)

{

cout<<"NO MATCH! TRY AGAIN"<<endl;

}

attempts--;

}

//If all attempts done

if(attempts==0)

{

cout<<"================================================"<<endl;

cout<<"ACCESS DENIED"<<endl;

cout<<"GOODBYE"<<endl;

cout<<"================================================"<<endl;

}

}

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