SHARE
TWEET

Untitled

a guest Jun 19th, 2017 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Jonas Cooper 10/5/10 Sentence Analyzer
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <fstream>
  5. #include <string>
  6. #include <cmath>
  7.  
  8. using namespace std;
  9.  
  10.  
  11. double countVowels(string sentence);
  12.  
  13. double countConsonants(string sentence);
  14. /*
  15. double findLongest(int longLength);
  16. double findShortest(int shortLength);
  17. */
  18.  
  19. int main()
  20. {   cout<<"This program will take a sentence of intput and return the number of vowels.";
  21.     string sentence;
  22.     cout<<endl;
  23.     cout<<"Enter a line of text.";
  24.     getline(cin, sentence);
  25.     int i;
  26.     i = 0;
  27.     sentence.at(i);
  28.     cout<<"The number of vowels is: "<<countVowels(sentence);
  29.     cout<<endl;
  30.     cout<<"The number of consonants is: "<<countConsonants(sentence);
  31.     cout<<endl;
  32.  
  33.         system("pause");
  34. /*
  35. get the sentence input from the user and store it in a variable
  36. use a for loop from i=0 to i< sentence.length() to look at each character in the string. (The characters are stored by their index so sentence(i) will give the character at position i)
  37. Next, use a switch and if sentence(i) is A E I O U then increment a counter variable.
  38. */
  39.  
  40.  
  41.  
  42.  
  43. return 0;
  44. }
  45.  
  46.  
  47. //FUNCTION ONE
  48. //Counts Vowels
  49. double countVowels(string sentence)
  50. {
  51.  
  52.     int vowels = 0;
  53.      for(int i=0; i<sentence.length(); i++) {
  54.         char currentLetter = sentence[i];
  55.         currentLetter = toupper(currentLetter);
  56.         switch(currentLetter) {
  57.         case 'A':
  58.         case 'E':
  59.         case 'I':
  60.         case 'O':
  61.         case 'U':
  62.  
  63.    vowels++;
  64.    cout<<endl;
  65.    break;
  66.         }
  67.     }
  68.      return vowels;
  69. }
  70. //FUNCTION TWO
  71. //counts conconants
  72. double countConsonants(string sentence)
  73. {
  74.  
  75. int cons = 0;
  76.      for(int i=0; i<sentence.length(); i++) {
  77.         char currentLetter = sentence[i];
  78.         currentLetter = toupper(currentLetter);
  79.         switch(currentLetter) {
  80.         case 'A':
  81.         case 'E':
  82.         case 'I':
  83.         case 'O':
  84.         case 'U':
  85.         case ' ':
  86.         case '.':
  87.         case ',':
  88.         case '?':
  89.         case '!':
  90.         case '-':
  91.  
  92.  
  93.         default :
  94.             cons++;
  95.    cout<<endl;
  96.    break;
  97.         }}
  98. return cons;
  99.  
  100. }
  101.         /*
  102. double findLongest(int longLength)
  103. {
  104.  
  105. }
  106. double findShortest(int shortLength)
  107. {
  108.  
  109. */
RAW Paste Data
Top