Question

In: Computer Science

Write a boolean function named isMember that takes two arguments: an array of type char and...

Write a boolean function named isMember that takes two arguments: an array of type
char 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.

PLEASE WRITE FULL PROGRAM IN C++ AND USE RECURSION AND DO NOT USE LOOPS

Solutions

Expert Solution

#include<iostream>
using namespace std;

bool isMember(char arr[],int n,char ch)
{
    if(arr[n]==ch)              //base condition.
        return true;
    if(arr[n]!=ch&&n<=0) //base condition
            return false;

    return isMember(arr,n-1,ch);

}
int main()
{
        char arr[]={'a','b','c','d'};
        int n=4;
        char ch1='a';
        char ch2='e';

        if(isMember(arr,n-1,ch1))
          cout<<"value:"<<ch1<< " founded\n";
        else
          cout<<"value:"<<ch1<<" NOT found\n";


        if(isMember(arr,n-1,ch2))
          cout<<"value:"<<ch2<< " founded!!!!\n";
        else
          cout<<"value:"<<ch2<<" NOT found\n";
}

Output:


Related Solutions

Write a function named hasNValues which takes an array and an integer n as arguments. It...
Write a function named hasNValues which takes an array and an integer n as arguments. It returns true if all the elements of the array are one of n different values. If you are writing in Java or C#, the function signature is int hasNValues(int[ ] a, int n) If you are writing in C or C++, the function signature is int hasNValues(int a[ ], int n, int len) where len is the length of a Note that an array...
2 Write a function named equivalentArrays that has two array arguments and returns 1 if the...
2 Write a function named equivalentArrays that has two array arguments and returns 1 if the two arrays contain the same values (but not necessarily in the same order), otherwise it returns 0. Your solution must not sort either array or a copy of either array! Also you must not modify either array, i.e., the values in the arrays upon return from the function must be the same as when the function was called. Note that the arrays do not...
c++ Write the definition of a function named ‘isLower’ that takes as input a char value...
c++ Write the definition of a function named ‘isLower’ that takes as input a char value and returns true if the character is lowercase; otherwise, it returns false.•Print the message “The character xis lowercase” when returned value above is true, and vice versa.
(In python) 4. Write a function that involves two arguments, named changeTheCase(myFile, case), that takes, as...
(In python) 4. Write a function that involves two arguments, named changeTheCase(myFile, case), that takes, as arguments, the name of a file, myFile, and the case, which will either be “upper” or “lower”. If case is equal to “upper” the function will open the file, convert all characters on each line to upper case, write each line to a new file, named “upperCase.txt”, and return the string “Converted file to upper case.” If case is equal to “lower” the function...
Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++, using pass by reference
Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++
a splitting function, split_by Write a splitting function named split_by that takes three arguments an equality...
a splitting function, split_by Write a splitting function named split_by that takes three arguments an equality checking function that takes two values and returns a value of type bool, a list of values that are to be separated, and a list of separators values. This function will split the second list into a list of lists. If the checking function indicates that an element of the first list (the second argument) is an element of the second list (the third...
. Write   a   function   that   takes,   as   arguments,   two   objects,   value1   and   value2.       If  
. Write   a   function   that   takes,   as   arguments,   two   objects,   value1   and   value2.       If   value1   and   value2   are   either   integers   or   strings   containing   only   digits,   cast   value1   and   value2   to   integers   and   compute   their   average.       If   their   average   is   greater   than   50,   return   the   string   “Above   50”   and   if   the   average   is   less   than   50,   return   the   string   “Below   50”.       If   the   average   is   equal   to   50,   return   the   string   “Equal   to   50”,   and   if   value1   or  ...
Requirements: C++ Array/File Functions Write a function named arrayToFile. The function should accept 3 arguments: The...
Requirements: C++ Array/File Functions Write a function named arrayToFile. The function should accept 3 arguments: The name of the file, a pointer to an array, and the size of the array. The function should open the specified file in binary mode, write the contents of the array to file, and then close the file. Write another function named fileToArray. This function should accept 3 arguments: the name of the file, a pointer, to an int array, and the size of...
Write a Java method that takes an array of char and a String as input parameters...
Write a Java method that takes an array of char and a String as input parameters and and returns an boolean. The method returns true if we can find the input string inside the array by starting at any position of the array and reading either forwards or backwards.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT