Advertisement
baexie

c++.com daily 20120718

Jul 27th, 2012
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. //master.cpp
  2. #include <iostream>
  3. #include <string>
  4. #include <string.h>
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. using namespace std;
  8.  
  9. // Declarations
  10. string myString;
  11.  
  12. // Functions
  13. bool IsVowel(char stringElement);
  14. string RemoveVowels(string inString);
  15.  
  16. // Main
  17. int main()
  18. {
  19.  
  20.     cout << "Welcome, enter a string to remove vowels from:" << endl;
  21.     getline (cin,myString);
  22.     myString = RemoveVowels(myString);
  23.     cout << endl << "Your string without vowels: " << myString << endl << endl;
  24.     system("pause");
  25.  
  26. }
  27.  
  28. // Functions Body
  29. bool IsVowel(char stringElement)
  30. {
  31.     if (isupper(stringElement))
  32.     {
  33.         tolower(stringElement);
  34.     }
  35.        
  36.     if (stringElement == 'a' || stringElement == 'e' || stringElement == 'i' || stringElement == 'o' || stringElement == 'u' || stringElement == 'y')
  37.     {
  38.         return true;
  39.     }
  40.     else
  41.     {
  42.         return false;
  43.     }
  44. }
  45.  
  46.  
  47. string RemoveVowels(string inString)
  48. {
  49.     unsigned int i = 0;
  50.     while (i < inString.length())
  51.     {
  52.         if (IsVowel(inString[i]))
  53.         {
  54.             inString.erase(i,1);
  55.         }
  56.         else
  57.         {
  58.             i++;   
  59.         }
  60.     }
  61. return inString;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement