سلام عليكم
انا سويت البرنامج بس يطلع انه في ايرور ما ادري ليش ..
هي السؤال :
Write a function template named searching(.. ) that search in an array for a key value. The array, key value, and the size of the array should be passed as parameters to the function searching. If the key is found, the function should return the position of the key in the array; otherwise it should return -1. The elements of the array could be of any basic type.
Write a main function that calls the above function searching( ) three times with an integer, a double and a character array.
وهي البرنامج اللي سويته:
#include<iostream>
using namespace std;
template < class T>
T searching (T a[],T size,T key)
{
for ( int i=0;i<size;i++)
{
if (a[i]== key)
return i;
}
return -1;
}
int main()
{
int x[]={1,2,3,7,8};
double y[]={1.3,1.9,1.5,7.6,4.1,1.7};
char z[]={'z','e','r','i','k','o','l'};
cout<<searching(z,7,'h');
cout<<searching(y,6,1.3);
cout<<searching(x,5,'o');
return 0;
}
وشكراا مقدما :) ...
نوران