#include<iostream.h>
#include<conio.h>
class Array
{
private:
int x[10],key,pos,n,i;
public:
void read();
void process();
};
void Array::read()
{
cout<<"\n--------------------------------------------------------------";
cout<<"\nEnter The Size Of Array\n";
cin>>n;
cout<<"\n--------------------------------------------------------------";
cout<<"\nEnter Elements of Array\n";
for(i=1;i<=n;i++)
cin>>x[i];
cout<<"\n--------------------------------------------------------------";
}
void Array::process()
{
cout<<"\nEnter Element to Search\n";
cin>>key;
cout<<"\n--------------------------------------------------------------";
x[n+1]=key;
for(i=1;i<=n;i++)
{
if(x[i]==key)
{
pos=i;
break;
}
}
if(pos<=n)
cout<<"\nSearch Successfull The Element is located at position no.:"<<pos<<".";
else
cout<<"\nSORRY!Search Unuccessfull The Element is NOT FOUND..";
cout<<"\n--------------------------------------------------------------";
}
void main()
{
clrscr();
Array a;
cout<<"\n-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-";
cout<<"\n -*- Program For Linear Search Method -*-";
cout<<"\n-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-";
a.read();
a.process();
getch();
}
#include<conio.h>
class Array
{
private:
int x[10],key,pos,n,i;
public:
void read();
void process();
};
void Array::read()
{
cout<<"\n--------------------------------------------------------------";
cout<<"\nEnter The Size Of Array\n";
cin>>n;
cout<<"\n--------------------------------------------------------------";
cout<<"\nEnter Elements of Array\n";
for(i=1;i<=n;i++)
cin>>x[i];
cout<<"\n--------------------------------------------------------------";
}
void Array::process()
{
cout<<"\nEnter Element to Search\n";
cin>>key;
cout<<"\n--------------------------------------------------------------";
x[n+1]=key;
for(i=1;i<=n;i++)
{
if(x[i]==key)
{
pos=i;
break;
}
}
if(pos<=n)
cout<<"\nSearch Successfull The Element is located at position no.:"<<pos<<".";
else
cout<<"\nSORRY!Search Unuccessfull The Element is NOT FOUND..";
cout<<"\n--------------------------------------------------------------";
}
void main()
{
clrscr();
Array a;
cout<<"\n-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-";
cout<<"\n -*- Program For Linear Search Method -*-";
cout<<"\n-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-";
a.read();
a.process();
getch();
}
No comments:
Post a Comment