Write a sub procedure using a for next loop to extract all the vowls from the string | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

Write a sub procedure using a for next loop to extract all the vowls from the string

25th Sep 2017, 11:47 AM
Dries
Dries - avatar
1 Réponse
+ 5
What's a for next loop? Do you mean for_each()? Function 1 - Without for_each, just plain for. bool isvowel(char c) { return c=='a' || c=='e' || c=='i' || c=='o' \ || c=='u' || c=='A' || c=='E' || c=='I' || \ c=='O' || c=='U' ; } string extract(string data) { string res(""); int len = data.length(); for(int i=0;i<len;i++) { if( isvowel(data.at(i) ) res += data.at(i); } return res; } Function 2 - Using for_each and iters. C++11. string res(""); //Global void vowel(char c) { if (c=='a' || c=='e' || c=='i' || c=='o' \ || c=='u' || c=='A' || c=='E' || c=='I' || \ c=='O' || c=='U' ) res += c; } string extract(string data) { for_each(data.begin(),data.end(),vowel); string dat(res); return dat; }
25th Sep 2017, 12:51 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar