hi

Write an overload function "searchArray" so that it takes an
array "ary" of int or char, and additional argument,
namely "valu" with type as same as the "ary". A call to this
function will return the index of "valu" within "ary" or -1
if it does not exist.


and this is what i could write for now ..

int searchArray ( int ary[ ],int a){
for ( int i=0;i<=ary.length;i++){
if (ary[i]== a)
return i;
else
return -1;
}

}

it's not complete ..
any one can help me and make it 100% work

thanks

for the general search function, take the else return -1 out of the for loop. That return statement should only execute if you complete the for loop and don't find the search value. int ary[] does not have a length member. You will have to pass the array length as an additional parameter.

If you google C++ templates you'll find a wealth of information on how to use them - as well as, maybe, reading your textbook? Take a stab at it and show us your work then.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.