1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <cstdlib>
#include <iostream>
using namespace std;
#include <string>
template <class Anytype>
bool search(Anytype ary[], Anytype key, int size)
{
int j; bool notFound = false;
j=0;
while(j<=size&¬Found==false)
{
if(key==ary[j])
notFound = true;
else
++j;
}
return notFound;
}
int main()
{
float a[]={3.2,4.8,9.1,15.99}, float_key;
int b[] = {12,1,8}, int_key;
cout<<"Enter float key: "<<endl;
cin>>float_key;
cout<<"Enter int key: "<<endl;
cin>>int_key;
float z;
z = search(a,float_key,4);
cout<<"If 1, float value entered was in array, if 0, float value was not in array :"<<z<<endl;
int t;
t = search(b,int_key,3);
cout<<"If 1, int value entered was in array, if 0, int value was not in array :"<<t<<endl;
system("PAUSE");
}
|