Linear search by
making class and functions
Linear search which is good for small data. Make a class
array and some functions to make linear search easiy.
#include<iostream.h>
const int size = 10;
class array
{
private:
int a[size];
int n;
public:
array()
{
for ( int i=0; i<size; i++ )
{
a[i];
n = 0;
}
}
void read()
{
int num;
cout<<"how many values you want to insert ?? "<<endl;
cin>>num;
for ( int i = 0; i<num; i++)
{
cout<<"Enter value: "<<endl;
cin>>a[i];
}
n = num;
}
void display ()
{
for (int i = 0; i<n; i++ )
cout<<a[i]<<endl;
}
void search()
{
bool Found = false;
int key;
cout<<"enter key: "<<endl;
cin>>key;
for(int i= 0; i<n && !Found; i++)
if (key == a[i])
if(Found)
{
bool Found = true;
}
if(Found)
{
cout<<"found"<<endl;
}
else
{
cout<<"not found"<<endl;
}
}
};
void main()
{
array arr;
arr.read();
cout<<"The entered values are: "<<endl;
arr.display();
arr.search();
}