Advertisement
Need4Sleep

main.cpp (DailyC++) 7/18/12

Jul 23rd, 2012
1,951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. /// http://www.cplusplus.com/forum/beginner/75558/
  2. #include <iostream>
  3. #include <string.h>
  4. #include <cstdlib>
  5. #include <algorithm>
  6. bool vowel(std::string str);
  7. void remove(std::string & str);
  8.  
  9. int main()
  10. {
  11.     std::string word;
  12.     std::cout << "Welcome to the vowel remover! enter any word: ";
  13.     std::cin >> word;
  14.     if(!vowel(word))
  15.         std::cout << "No vowels detected in: " << word << ".\n";
  16.     else
  17.         remove(word);
  18.  
  19. }
  20.  
  21. bool vowel(std::string str)
  22. {
  23.     std::transform(str.begin(), str.end(), str.begin(), ::tolower);
  24.     for(int i = 0;i<str.length();i++)
  25.     {
  26.         if(str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u')
  27.                 return true;
  28.     }
  29.     return false;
  30. }
  31.  
  32. void remove(std::string & str)
  33. {
  34.     std::string vowellesswrd;
  35.     for(int i = 0; i < str.length(); i++)
  36.     {
  37.         std::string temp;
  38.         temp = str[i];
  39.         if(!vowel(temp))
  40.             vowellesswrd += str.substr(i,1);
  41.  
  42.     }
  43.     std::cout << str << " with no vowels becomes: " << vowellesswrd << std::endl;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement