Posted By

Desoxena on 01/10/11


Tagged


Versions (?)

C++ string --> 1 & 0's


 / Published in: C++
 

you enter in a string, and it will convert the consonants to 1's, and the vowels to 0's. spaces are not really supported, replace spaces with ".", or "-".

  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. int i=0, j;
  11. string word;
  12. cin >> word;
  13. do{
  14. if(word.at(i) == 'a'||
  15. word.at(i) == 'e'||
  16. word.at(i) == 'i'||
  17. word.at(i) == 'o'||
  18. word.at(i) == 'u')
  19. {
  20. word.replace(i, 1, "0");
  21. i++;
  22. }
  23. else if(word.at(i) == 'b'||
  24. word.at(i) == 'c'||
  25. word.at(i) == 'd'||
  26. word.at(i) == 'f'||
  27. word.at(i) == 'g'||
  28. word.at(i) == 'h'||
  29. word.at(i) == 'j'||
  30. word.at(i) == 'k'||
  31. word.at(i) == 'l'||
  32. word.at(i) == 'm'||
  33. word.at(i) == 'n'||
  34. word.at(i) == 'p'||
  35. word.at(i) == 'q'||
  36. word.at(i) == 'r'||
  37. word.at(i) == 's'||
  38. word.at(i) == 't'||
  39. word.at(i) == 'v'||
  40. word.at(i) == 'w'||
  41. word.at(i) == 'x'||
  42. word.at(i) == 'y'||
  43. word.at(i) == 'z')
  44. {
  45. word.replace(i, 1, "1");
  46. i++;
  47. }
  48. else if(word.at(i) == ' '||word.at(i) == '-'||word.at(i) == '.')
  49. {
  50. word.replace(i, 1, " ");
  51. i++;
  52. }
  53. system("cls");
  54. cout << word << endl;
  55. }while (i != word.length());
  56. system("pause");
  57. }

Report this snippet  

You need to login to post a comment.