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

You have been hired as a programmer at the local bank where you are dealing with

ID: 3702406 • Letter: Y

Question

You have been hired as a programmer at the local bank where you are dealing with records of customers registered at the bank. Your job is to locate the record number of the customer’s account that is associated with the bank. The records are all stored in the database as a 2D matrix. You have to write a program in C++ in such a way that you when given a particular number you return true if the record exists or return false when the record does not exist.

All the records are in an un-sorted order which means:

1. Sort the integers first row-wise (use bubble sort).

2. Search for the particular element. Your code must be optimal as the records being fetched must be fast. In order to maintain that it must never contain nested for or while loops. (hint: Use binary search)

************WE HAVE NOT LEARNED ABOUT stdio.h**********

Input Scenarios: Input 1: [10,16,14,20,21] [28,56,64,24,67] Element to be searched is: 70 Input 2: [2,6,10,8] [14,12,16,18] [23,25,24,27] 134,31,33,35)] Element to be searched is: 25 Input 3: [5,3,7,9,11] [13,16,18,21,20] Element to be searched is: 13

Explanation / Answer

#include <iostream>

using namespace std;

int binarysearch(int arra[][3],int low,int high,int middle,int ele,int rownumber)  
{
while (low <= high)
{
if (arra[rownumber][middle] < ele)
{
low = middle + 1;
}
else if (arra[rownumber][middle] == ele)
{
return 1;
}
else
{
high = middle - 1;
}

middle = (low + high)/2;
}
return 0;
}

int main()
{
int Rows,Columns,i,j,k,temp,Element,result=0;
  
// std::cout << "Enter the number of Rows:-" << std::endl; // printf("Enter the number of Rows:-");
// std::cin >> Rows; // scanf("%d",&Rows);
// std::cout << "Enter the number of Columns:-" << std::endl; // printf("Enter the number of Columns:-");
// std::cin >> Columns; // scanf("%d",&Columns);
Rows=3;
Columns=3;
cout<<" "; // printf(" ");
int arr[3][3];
  
  
//taking input elements from user//
for(i=0;i<Rows;i++)
{
std::cout << "Enter Row " << i+1<<" elements."<<" " << std::endl; // printf("Enter Row %d elements. ",i+1);
  
for(j=0; j<Columns;j++)
{
std::cin >> arr[i][j]; // scanf("%d",&arr[i][j]);
  
}
  
}
  
//Sorting the elements of array row wise usng bubble sort//
for (k=0;k<Rows;k++)
{
for (i = 0 ; i < (Columns-1); i++)
{
for (j = 0 ; j <(Columns- i - 1); j++)
{
if (arr[k][j] > arr[k][j+1])
{
temp = arr[k][j];
arr[k][j] = arr[k][j+1];
arr[k][j+1] = temp;
  
}
  
}
  
}
  
}
  
std::cout <<" " <<"Element to be searched:" << std::endl; // printf(" Element to be searched:");
std::cin >> Element; // scanf("%d",&Element);
  
int lw,hg,mid;
lw = 0;
hg = Columns-1;
mid = (lw+hg)/2;
for(i=0;i<Rows;i++)
{
result=binarysearch(arr,lw,hg,mid,Element,i);  
if(result==1)
{
std::cout << "True" << std::endl; // printf("True");
break;
}
else if(result==0 && i==Rows-1)
{
std::cout << "False" << std::endl; //printf("False");
}
}

return 0;
}

Description:-here is the program for your searcha algorithm,make sure you use the 3*3 matrix.if you want to use the more bigger matrix change the array size in binarysearch function to your desired rows and columns,which is written after the header files.after that you can input these changed rows columns from the console input..if you found any error please feel free to Comment.I am there to thelp you.Thanks looking for your good response

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