Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 check the array for the order of the data (random, ascending order, or descending order)

The program will search the data for a specific value using a sequential and/or binary search algorithm

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

Program will contain four simple functions described below

*/

#include // required header file for input/output

using namespace std;

// function prototypes

void input_data(short data[], short size);

void binary_search(short data[], short size, short search_value, short &offset);

void check_order(short data[], short size, short &order);

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

int main()

{ // declare local variables

short order, search_again, size; // list not complete, you included additional variables as required/needed

// input the number of values to store in the array

while(size>0)

{

// call the function to input the data into the array

// call check_order function to determine if data is random or ordered

// display a message about the order of the data

(random, ascending or descending)

do // posttest loop will execute at least one time

{

// input a search value

if( order <= 0)

{

// call sequential_search function

// display a message to output the element # where search value was found or message value not found IF test

}

else if(order > 0) // data in ascending order

{

// call binary_search function

// display a message to output the element # where search value was found or message value not found IF test

// call sequential_search function

// display a message to output the element # where search value was found or message value not found - IF test

}

cout<<"To search for another number enter the digit 1 otherwise enter the digit 0 ";

cin>>search_again;

}while(search_again != 0);

cout<<"To process another date set enter the size of the data set or 0 to terminate the program ";

cin>>size;

} // end of while loop

// pause the program to see the results LEAVE THE FOLLOWING STATEMENT IN THE PROGRAM

//system("pause"); // this is a windows command; will not work in another operating system

//return 0; // optional statement, may be required for .NET compiler

}

// function definitions are placed after main

//

Do not output anything from the input_data function

// 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 binary search algorithm.

// return the subscript/element # where found or return -1 if not found.

void binary_search(short data[], short size, short search_value, short &offset)

{ /*code in function*/ }

// Function to check the order of the data

// Assign a

0

to

order

if random;

-1

to

order

if descending order, otherwise assign a

1

to

order

if ascending order

void check_order(short data[], short size, short &

order

)

{ /*code in function*/ }

// Function to search the array using a sequential search algorithm.

// Assign the subscript/element # to offset where found or assign offset -1 if not found.

// find the first occurrence of the search value

void sequential_search(short data[], short size, short search_value, short &offset)//

{ /*code in function*/ }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago