Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //--------------------------------------------------------------------------------------//
- // APSC 177 Assignment 7
- // Date:
- // Name:
- // Student ID Number:
- // Brief Description:
- //--------------------------------------------------------------------------------------//
- #include <iostream>
- #include <string>
- using namespace std;
- int main ()
- {
- int voweltally, contally, uppertally, lowertally, punctally, wordtally;
- string text;
- int i;
- cout << "Enter some text. Letters and the following punctuation only please . , : ; ! ?" << endl;
- cout << "Pressing enter/return will end the text." << endl;
- getline (cin, text);
- //------------------------------------------------------------------------------------------------------------------------------------------------//
- for( i = 0; i < text.length(); i++)
- {
- if( text[i]=='a' || text[i]=='A' || text[i]=='e' || text[i]=='E' || text[i]=='i'
- || text[i]=='I' || text[i]=='o' || text[i]=='O' || text[i]=='u' || text[i]=='U')
- voweltally++;
- else if((text[i] >= 'b' && text[i] <= 'z') || (text[i] >= 'B' && text[i] <= 'Z'))
- contally++;
- }
- //------------------------------------------------------------------------------------------------------------------------------------------------//
- for( i = 0; i < text.length(); ++i)
- {
- if(text[i] >= 'a' && text[i] <= 'z')
- lowertally++;
- else if(text[i] >= 'A' && text[i] <= 'Z')
- uppertally++;
- }
- //------------------------------------------------------------------------------------------------------------------------------------------------//
- for( i = 0; i < text.length(); i++)
- if(text[i] == '.' || text[i] == ',' || text[i] == ':' || text[i] == ';' || text[i] == '!' || text[i] == '?')
- punctally++;
- //------------------------------------------------------------------------------------------------------------------------------------------------//
- for( i = 0; i < text.length(); i++)
- if(text[i] == ' ' && text[i-1] != ' ')
- wordtally++;
- //------------------------------------------------------------------------------------------------------------------------------------------------//
- cout << "The number of vowels is: " << voweltally << endl;
- cout << "The number of consonants is: " << contally << endl;
- cout << "The number of uppercase letters is: " << uppertally << endl;
- cout << "The number of lowercase letters is: " << lowertally << endl;
- cout << "The number of punctuation characters is: " << punctally << endl;
- cout << "The number of words is: " << wordtally << endl;
- cout << "Exiting program ..." << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement