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

this program must run multiple times without having to run the program again. Yo

ID: 3703239 • Letter: T

Question

this program must run multiple times without having to run the program again.

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 returrn 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)

Explanation / Answer

#include <iostream>

using namespace std;

//call this method to sort matix and search the element
void bubbleSortMatrix(int mat[][100], int x ,int y, int element)
{
int i,j,k,row, column;
for(i=0;i<x;i++){
for(j=0;j<y;j++){
for(k=j+1;k<4;k++){
if(mat[i][j]>mat[i][k])
{
int temp = mat[i][j];
mat[i][j] = mat[i][k];
mat[i][k] = temp;
}
}
}
}
  
//print the sorted matrix and find if element is present  
for(i=0;i<x;i++)
{
for(j=0;j<y;j++){
if(mat[i][j] == element){
row = i;
column = j;
}
cout<<mat[i][j]<<" ";
cout<<" ";
}
}
  
if(row >=0 || column >=0){
cout <<"Element found at" << row <<":" << column;
}
else{
cout << " Element not found" <<"endl";
}
  

}

// Give input matrix and element to be searched and call required sort and search function
int main()

{
int x = 2, y = 5, element;

int mat[][100] = {{5, 3, 7, 9, 11},
{13, 16, 21, 18, 20}};

cout << "Input Matrix is " << mat <<endl;

cout << "Enter the number to be searched" << endl;

cin>>element;

cout << "Number to be searched is " << endl;
  

bubbleSortMatrix(mat, x, y, element);

return 0;
}