Last active
November 17, 2015 04:52
-
-
Save ronalddas/58bb29bffad700d9d077 to your computer and use it in GitHub Desktop.
A program to input, display, and search an element using linear search in an integer array using the concept of OOP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class CLASSONE | |
{ | |
public: | |
void LinearSearch(int a[],int key,int size) | |
{ | |
int i,counter =0; | |
for(i =0 ; i < size ; i++ ) | |
{ | |
if(a[i]== key) | |
{ | |
cout<<"Element found! at "<<i+1<<" position\n"; | |
counter =1; | |
} | |
} | |
if(counter ==0) | |
cout<<"Element not found\n"; | |
} | |
}; | |
int main(void) | |
{ | |
int b[50],n,i,j; | |
cout<<"Enter array size\n"; | |
cin>>n; | |
cout<<"Enter elements \n"; | |
for(i = 0; i < n; i++) | |
cin>>b[i]; | |
cout<<"The array is \n"; | |
for( i = 0 ; i < n; i++) | |
cout<<b[i]<<endl; | |
cout<<"Enter element to be searched\n"; | |
cin>> j; | |
CLASSONE objectOne; | |
objectOne.LinearSearch(b,j,n); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment