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

Generate a two dimensional test vector of integers by using random number genera

ID: 3669180 • Letter: G

Question

Generate a two dimensional test vector of integers by using random number generator, integers should be in [0,70]; the vector size should be 4 rows and 5 columns.(4*5) Let the user input number to be searched, use linear search function to search the number in the two dimensional vector The function should accept one two dimensional vector of integers and a number to search for. If the number is found (if there are duplicate numbers, get the first one), print out the number and "Number found!", and output the rows and columns. If not print out "Number isn't found!". You may need iterator to search, keep doing steps above until get negative integers Name your function "LinearSearch" Generate a one dimensional array of integers by using random number generator, integers should be in [0,70]; the array size should be 20 Let the user input number to be searched, if you can use binary search in the array? If so, use binary search function to search the number in the array; If not, explain why, fix it and then use binary search function to search the number in the array. The function should accept one array and a number to search for. If the number is found (if there are duplicate numbers, get the first one), print out the number and "Number found!", and output the original position. If not print out "Number isn't found!". You may use data structure for the array, and you may use other pointer or index for array

Explanation / Answer

Program 1:

#include<iostream.h>

#include<vector.h>

#include<cstdlib.h>

#include<ctime.h>

using namespace std;

vector<vector<int>>Vec(4, vector<int>(5));

int linear_search(vector<vector<int>> v, int s)

{

void print(vector<vector<int>> v)

{

{

cout<<v[row][col]<<" ";

}

cout<<" ";

}

}

void rand_numbers()

{

int number= static_cast<int>(time(0));

srand(number);

}

int rand_digit(int a , int b)

{

return a+rand() % (b-a+1);

}

int main()

{

rand_numbers();

vector<vector<int>> Vec(4, vector<int>(5));

{

Vec[row][col]= rand_digits(0,70);

print(Vec);

}

}

cout<<"enter the number to search:";

int num;

cin>>num;

int j= linear_search(Vec, num);

if(j==1)

cout<<"number not found";

else

cout<<"the element found"<<j;

cout<<" ";

return 0;

}

Program 2:

#include<iostream.h>

#include<conio.h>

#include<cstdlib.h>

#include<ctime.h>

using namespace std;

void rand_numbers()

{

int number= static_cast(time(0));

srand(number);

}

int rand_digits(int a , int b)

{

return a+rand() % (b-a+1);

}

int main()

{

rand_numbers();

int array[];

cout<<"enter size of array";

cin>>n;

cout<<"enter the number to search:";

int num;

cin>>num;

int start,end,midpoint;

start=0;

end= n-1;

while(start<=end)

{

midpoint=(start+end)/2;

if(array[midpoint]== num)

{

cout<<"number"<<num<<" found at position"<<(midpoint+1);

exit(0);

}

if(num> array[midpoint])

{

start=midpoint+1;

}

else

end=midpoint-1;

}

cout<<"number not found";

return 0;

}

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