Write code in C++, using the correct headers not the catchall std/bitsc:
Write a recursive, bool-valued function, containsVowel, that
accepts a string and returns true if the string contains a
vowel.
A string contains a vowel if:
it should be making use of true/false as it is a boolean, substr(), find, and !=.
#include<iostream> using namespace std; bool containsVowel(string s){ if(s.length()>0){ char ch = s[0]; if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'){ return true; } else{ return containsVowel(s.substr(1,s.length()-1)); } } else{ return false; } } int main() { cout<<containsVowel("yes"); return 0; }
1
Get Answers For Free
Most questions answered within 1 hours.