Answer:
The method definition to this question as follows:
Method definition:
bool containsVowel (string s1) //define method.
{
bool value=false; //define bool variable and assign value.
//check conditions.
if (s1.length()==0) //if block
{
return false; //return value
}
else if (s1[0]=='a'||s1[0]=='e'||s1[0]=='u'||s1[0]=='o'||s1[0]=='i'||s1[0]=='A'||s1[0]=='E'||s1[0]=='U'||s1[0]=='O'||s1[0]=='I') //else if block
{
value=true; //return value.
}
else //else block
{
value = containsVowel(s1.substr(1,s1.length()-1));//calculate value
return value; //return value.
}
}
Explanation:
In the above code, we define a bool method that is "containsVowel" in this method we pass the string variable that is "s1". Inside a method, we define a bool variable that is "value" and conditional statement that checks in the passed value there is a vowel or not.
- In if block, we check that pass variable value length is equal to 0. if this condition is true it will return a false value.
- Then we use else if block in this block we check that if value first letter is vowel to check this condition we use OR logical operator. if this condition is true it will change the variable value that is "true".
- In the else block we use the value variable that uses the function to check that in passed value there is a vowel if this is true it returns its value.