This is direction. isMember function Write a boolean function named isMember tha
ID: 3540013 • Letter: T
Question
This is direction.
isMember function
Write a boolean function named isMember that takes three arguments: an array, its
size (number of elements) and a value. It should return true if the value is found in
the array, or false if the value is not found in the array. oh~~ and can you change my functions using template too
igonore somoe powerfunction and those stuff those functions are working but.
searching in array has problem . my coding is not work actually. i dont know why, i got
random number after compiling.
please help me and tell me what is wrong. and my out put is 1 or random num not ture or false
out put suppose to be like
Member function
1 2 3 4 5 has 4?: YES
1 2 3 4 5 has 6?: NO
thanks u!
************************************************************************************************
Here is my code~
bool isMember(int array[],int size, int value)
{
bool status=false;
if(size<=0) p="">
return false;
else
{
if(array[size-1]==value)
return true;
else
return isMember(array,size-1,value);
}
return false;
}
int main()
{
float m=2;
int n=5;
float result;
int size=5;
int array[]={1,2,3,4,5};
int x=4;
int answer;
cout<<"table of="" squares:="" endl="" p="" span="" class="Apple-tab-span" cout="" n:="" n="" squared:="" tableofsquares="" 10="" result="" br="" power="" function:="" m="" to="" the="" th="" power:="" member="" answer="" system="" pause="" return="" 0="" div="" --="" table--="" data-mce-style="white-space: pre;">
Explanation / Answer
#include <iostream>
using namespace std;
bool isMember(int array[],int size, int value)
{
bool status=false;
if(size<=0)
return false;
else
{
if(array[size-1]==value)
return true;
else
return isMember(array,size-1,value);
}
}
int main()
{
float m=2;
int n=5;
float result;
int size=5;
int array[]={1,2,3,4,5};
int x=4;
int answer=isMember(array,size,x);
for (int i=0;i<size;i++)
{
cout<<array[i]<<" ";
}
cout<<"has "<<x<<"?:";
if(answer==0)
{
cout<<"NO";
}
else
{
cout<<"YES";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.