Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream> //allows access to the stream function
- using namespace std;
- //Part 1
- int countVowels(string input) // counts # of vowels in string input
- {
- int vowel = 0;
- for (int i = 0; i < input.size(); i++)
- {
- if (input[i] == 'a' || input[i] == 'A')
- {
- vowel++;
- }
- else if (input[i] == 'e' || input[i] == 'E')
- {
- vowel++;
- }
- else if (input[i] == 'i' || input[i] == 'I')
- {
- vowel++;
- }
- else if (input[i] == 'o' || input[i] == 'O')
- {
- vowel++;
- }
- else if (input[i] == 'u' || input[i] == 'U')
- {
- vowel++;
- }
- else if(input[i] == ' ')
- {
- }
- else
- {
- }
- }
- return vowel;
- }
- int countNonSpace(string input) //counts # of characters that aren't spaces
- {
- int nonSpace = 0;
- for (int i = 0; i < input.size(); i++)
- {
- if (input[i] == ' ')
- {
- }
- else
- {
- nonSpace++;
- }
- }
- return nonSpace;
- }
- int countWords(string input) //counts # of words
- {
- int wordCount = 1;
- for (int i = 0; i < input.size(); i++)
- {
- if (input[i] == ' ')
- {
- wordCount++;
- }
- else
- {
- }
- }
- return wordCount;
- }
- //Part 2
- void findWords(string input) //converts standard English into Pig Latin
- {
- istringstream ss(input);
- string word;
- while (ss >> word)
- {
- //begins with vowels
- if (word[0] == 'a' || word[0] == 'e' || word[0] == 'i' || word[0] == 'o' || word[0] == 'u' || word[0] == 'A' || word[0] == 'E' || word[0] == 'I' || word[0] == 'O' || word[0] == 'U')
- {
- cout << word + "lay" << ' ';
- }
- else //begins with consonants
- {
- for (int i = 0; i < word.size(); i++)
- {
- //until word hits a vowel
- if(word[i] == 'a' || word[i] == 'e' || word[i] == 'i' || word[i] == 'o' || word[i] == 'u' || word[i] == 'A' || word[i] == 'E' || word[i] == 'I' || word[i]== 'O' || word[i] == 'U' || word[i] == 'y' || word[i] == 'Y')
- {
- string part = word.substr(0, i);
- string phrase = word.erase(0, i);
- string newPhrase = phrase + part + "ay";
- cout << newPhrase << ' ';
- break;
- }
- else
- {
- }
- }
- }
- }
- system("pause");
- }
- int main()
- {
- string input;
- getline(cin, input); //gets the entire line of input
- cout << "There are " << countVowels(input) << " vowels." << endl;
- cout << "There are " << countNonSpace(input) << " characters that are not spaces. " << endl;
- cout << "There are " << countWords(input) << " words. " << endl;
- cout << "**********************************************************************" << endl;
- findWords(input);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement