Advertisement
Guest User

Vowels&Consonants

a guest
Oct 9th, 2015
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5. string getWord();
  6. int getVowel(string word);
  7. int getConsonants(string word);
  8. int displayVowel(int& sum1);
  9. int displayConsonants(int& sum2);
  10.  
  11. int main()
  12. {
  13. string word;
  14. int sum1;
  15. int sum2;
  16. word = getWord();
  17. getVowel(word);
  18. getConsonants(word);
  19. displayVowel(sum1);
  20. displayConsonants(sum2);
  21.  
  22. system("pause");
  23. return 0;
  24. }
  25. string getWord()
  26. {
  27. string word;
  28. cout << "what is the word ";
  29. getline(cin, word);
  30. return word;
  31. }
  32. int getVowel(string word)
  33. {
  34. int sum1 = 0;
  35. char temp;
  36. for (int i = 0; i < word.length(); i++)
  37. {
  38. if (isalpha(word.at(i)))
  39. {
  40. temp = word.at(i);
  41. temp = tolower(temp);
  42. if (temp == 'a' || temp == 'e' || temp == 'i' || temp == '0' || temp == 'u')
  43. sum1 += 1;
  44. }
  45.  
  46. }
  47. return sum1;
  48. }
  49. int getConsonants(string word)
  50. {
  51. int sum2 = 0;
  52. char temp;
  53. for (int i = 0; i < word.length(); i++)
  54.  
  55. if (isalpha(word.at(i)))
  56. {
  57. temp = word.at(i);
  58. temp = tolower(temp);
  59. if (temp != 'a' && temp != 'e' && temp != 'i' && temp != '0' && temp != 'u')
  60. sum2 += 1;
  61. }
  62. return sum2;
  63. }
  64.  
  65. int displayVowel(int& sum1)
  66. {
  67. cout << "The total number of vowels are " << sum1 << endl;
  68. return sum1;
  69. }
  70.  
  71. int displayConsonants(int& sum2)
  72. {
  73. cout << "The total number of consonants are " << sum2 << endl;
  74. return sum2;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement