Question

follow the instructions inside. You are to implement the sequential search of array elements. User will...

follow the instructions inside.

You are to implement the sequential search of array elements.

User will enter a value (size) which represents the number of values to process

The values entered will be stored in an array of type short that has 1000 elements

User will enter size numbers

The user will enter a search value

The program will search the data for a specific value

program will display a message in which element the value was found or display a message the value was not found

*/

#include<iostream> // required header file for input/output

using namespace std;


// function prototypes
void input_data(short data[], short size);
void sequential_search(short data[], short size, short search_value, short &offset);

int main()
{ // declare local variables
  
int search_again;
  
// input the number of values to store in the array
  
// call the function to input the data into the array
  
do // posttest loop (will execute at least one time)
{
  
// input a search value
  
// call sequential_search function
  
// display a message to output the element # where search value was found or message value not found
  
  
cout<<"To search for another number enter the digit 1 otherwise enter the digit 0 ";
  
cin>>search_again;
  
} while(search_again != 0);
  
  
  
return 0;
  
}

// function definitions are placed after main
// Do not output anything from these functions
// Function to input(store) data into the array
void input_data(short data[], short size)
{ /*code in function*/ }


// Function to search the array using a sequential search
// Assign the subscript/element # to offset where found or assign offset -1 if not found.
void sequential_search(short data[], short size, short search_value, short &offset)//

{ /*code in function*/ }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

#include<iostream>// required header file for input/output

using namespace std;

// function prototypes

void input_data(short data[], int size);
void sequential_search(short data[], short size, short search_value, short &offset);

int main() {
// declare local variables

int search_again = 1, size;
short data[100], search_value;

// input the number of values to store in the array
cout<<"\nEnter size of the array : ";
cin>>size;

// call the function to input the data into the array
cout<<"\nEnter "<<size<<" elements one by one : ";
input_data(data, size);
short offset;
// call the function to sort the data in ascending order

do // posttest loop (will execute at least one time)
{
// input a search value
cout<<"\nEnter a value to search in the array : ";
cin>>search_value;

// call binarySearch function
sequential_search(data, size, search_value,offset);
// display a message to output the element # where search value was found or message value not found
if(offset!=-1)
cout<<"\n"<<search_value<<" was found at index "<<offset<<endl;
else
cout<<"Number not found"<<endl;
cout<<"\n\nTo search for another number enter the digit 1 otherwise enter the digit 0 : ";
cin>>search_again;

} while(search_again != 0);

cout<<"\n";
return 0;

}

//function definitions are placed after main

// Do not output anything from these functions

// Function to input(store) data into the array

void input_data(short data[], int size) {
for(int i =0; i<size; i++) {
cin>>data[i];
}

}
void sequential_search(short data[], short size, short search_value, short &offset) {
for (short i=0;i<size;i++)
{
if (data[i] == search_value) {
offset = i;
return;
}

}
offset = -1;
}

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
follow the instructions inside. You are to implement the sequential search of array elements. User will...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA Objectives: 1. Apply linear search algorithm 2. Apply select sort algorithm 3. Apply array iteration...

    JAVA Objectives: 1. Apply linear search algorithm 2. Apply select sort algorithm 3. Apply array iteration skill Problem description: Write the following eight methods and write a main function to test these methods // return the index of the first occurrence of key in arr // if key is not found in arra, return -1 public static int linearSearch(int arr[], int key) // sort the arr from least to largest by using select sort algorithm public stati void selectSort(int arr[])...

  • C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible;...

    C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible; (2) use unique value array; (3) use flag array (flags used to avoid counting a number more than 1 time); (4) compute frequency distribution (use unique and count arrays); (5) use count array to store the frequency of a number. No global variable are permitted in this assignment. Do not change the code provided only write the missing code. Write the missing C++ statements...

  • In C language Write a program that includes a function search() that finds the index of...

    In C language Write a program that includes a function search() that finds the index of the first element of an input array that contains the value specified. n is the size of the array. If no element of the array contains the value, then the function should return -1. The program takes an int array, the number of elements in the array, and the value that it searches for. The main function takes input, calls the search()function, and displays...

  • In C language Write a program that includes a function search() that finds the index of...

    In C language Write a program that includes a function search() that finds the index of the first element of an input array that contains the value specified. n is the size of the array. If no element of the array contains the value, then the function should return -1. The program takes an int array, the number of elements in the array, and the value that it searches for. The main function takes input, calls the search()function, and displays...

  • /* * Program5 for Arrays * * This program illustrates how to use a sequential search...

    /* * Program5 for Arrays * * This program illustrates how to use a sequential search to * find the position of the first apparance of a number in an array * * TODO#6: change the name to your name and date to the current date * * Created by Li Ma, April 17 2019 */ #include <iostream> using namespace std; //global constant const int ARRAY_SIZE = 10; //TODO#5: provide the function prototype for the function sequentialSearch int main() {...

  • * This program illustrates how to use a sequential search to find the position of the...

    * This program illustrates how to use a sequential search to find the position of the first apparance of a number in an array TODO#6: change the name to your name and date to the current date * * Created by John Doe, April 17 2019 */ #include using namespace std; //global constant const int ARRAY_SIZE = 10; //TODO#5: provide the function prototype for the function sequentialSearch int main() { //TODO#1: declare an integer array named intList with size of...

  • in c++ please Assignment Instructions: MAIN FUNCTION: Ask the user how many students were surveyed.   Call...

    in c++ please Assignment Instructions: MAIN FUNCTION: Ask the user how many students were surveyed.   Call a function called makeArray to define an array of integers with the number of elements equal to the number of students surveyed. Call a function called getStudentData to allow the user to enter the number of hours each student spent watching Netflix into the array. Call a function called getAverage to calculate and display the average of the hours entered. Call a function called...

  • In Java, Implement a class MyArray as defined below, to store an array of integers (int)....

    In Java, Implement a class MyArray as defined below, to store an array of integers (int). Many of its methods will be implemented using the principle of recursion. Users can create an object by default, in which case, the array should contain enough space to store 10 integer values. Obviously, the user can specify the size of the array s/he requires. Users may choose the third way of creating an object of type MyArray by making a copy of another...

  • Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring...

    Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring a variable, you usually want to initialize it. Remember you cannot initialize a number with a string. Remember variable names are case sensitive. Use tabs or spaces to indent code within blocks (code surrounded by braces). Use white space to make your program more readable. Use comments after the ending brace of classes, methods, and blocks to identify to which block it belongs. Problem...

  • C++ Time the sequential search and the binary search methods several times each for randomly generated...

    C++ Time the sequential search and the binary search methods several times each for randomly generated values, then record the results in a table. Do not time individual searches, but groups of them. For example, time 100 searches together or 1,000 searches together. Compare the running times of these two search methods that are obtained during the experiment. Regarding the efficiency of both search methods, what conclusion can be reached from this experiment? Both the table and your conclusions should...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT