Binary Search Write a C++ Program for searching an element on a given list of integers using the Binary Search method. Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names, member variable names, and function names should be the same as specified in the problem statement. Initialize the array size in the constructor of the Search class. Function Description int search(int n, int k) The function defines the logic for searching an element from the given array. If the element is found return '1'. Otherwise, return '0'. Input Format: The first line is an integer 'n' which corresponds to the number of elements in the array. The next 'n' lines correspond to the elements of the array. The last line is an integer 'k' which corresponds to the key element to be searched. Output Format: Print "Element Found" if the element is present in the array otherwise print "Element not Found". [All text in bold corresponds to the input and the rest corresponds to output] Sample Input and Output 1: 5 1 2 3 4 5 3 Element found Sample Input and Output 2: 4 3 5 7 9 11 Element Not Found

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 3PE
icon
Related questions
Question
Binary Search

Write a C++ Program for searching an element on a given list of integers using the Binary Search method.

Strictly adhere to the Object-Oriented specifications given in the problem statement. All class names, member variable names, and function names should be the same as specified in the problem statement.

Initialize the array size in the constructor of the Search class.
 

Function Description
int search(int n, int k) The function defines the logic for searching an element from the given array.
If the element is found return '1'. Otherwise, return '0'.


Input Format:
The first line is an integer 'n' which corresponds to the number of elements in the array.
The next 'n' lines correspond to the elements of the array.
The last line is an integer 'k' which corresponds to the key element to be searched.

Output Format:
Print "Element Found" if the element is present in the array otherwise print "Element not Found".

[All text in bold corresponds to the input and the rest corresponds to output]

Sample Input and Output 1:

5
1
2
3
4
5
3

Element found

Sample Input and Output 2:

4
3
5
7
9
11

Element Not Found

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning