Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Jonas Cooper 10/5/10 Sentence Analyzer
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- #include <string>
- #include <cmath>
- using namespace std;
- double countVowels(string sentence);
- double countConsonants(string sentence);
- /*
- double findLongest(int longLength);
- double findShortest(int shortLength);
- */
- int main()
- { cout<<"This program will take a sentence of intput and return the number of vowels.";
- string sentence;
- cout<<endl;
- cout<<"Enter a line of text.";
- getline(cin, sentence);
- int i;
- i = 0;
- sentence.at(i);
- cout<<"The number of vowels is: "<<countVowels(sentence);
- cout<<endl;
- cout<<"The number of consonants is: "<<countConsonants(sentence);
- cout<<endl;
- system("pause");
- /*
- get the sentence input from the user and store it in a variable
- 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)
- Next, use a switch and if sentence(i) is A E I O U then increment a counter variable.
- */
- return 0;
- }
- //FUNCTION ONE
- //Counts Vowels
- double countVowels(string sentence)
- {
- int vowels = 0;
- for(int i=0; i<sentence.length(); i++) {
- char currentLetter = sentence[i];
- currentLetter = toupper(currentLetter);
- switch(currentLetter) {
- case 'A':
- case 'E':
- case 'I':
- case 'O':
- case 'U':
- vowels++;
- cout<<endl;
- break;
- }
- }
- return vowels;
- }
- //FUNCTION TWO
- //counts conconants
- double countConsonants(string sentence)
- {
- int cons = 0;
- for(int i=0; i<sentence.length(); i++) {
- char currentLetter = sentence[i];
- currentLetter = toupper(currentLetter);
- switch(currentLetter) {
- case 'A':
- case 'E':
- case 'I':
- case 'O':
- case 'U':
- case ' ':
- case '.':
- case ',':
- case '?':
- case '!':
- case '-':
- default :
- cons++;
- cout<<endl;
- break;
- }}
- return cons;
- }
- /*
- double findLongest(int longLength)
- {
- }
- double findShortest(int shortLength)
- {
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement