Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- // takes a string and converts it to pig latin
- string Latin(string);
- int main()
- {
- cout<< "enter your statement that you want to translate"<<endl;
- string mySentence;
- getline(cin, mySentence);
- mySentence = Latin(mySentence);
- cout << mySentence << endl;
- return 0;
- }
- string Latin(string word)
- {
- string LatWord, LatSentence = "";
- int length = 0, index = 0;
- while (word[index] != '\0')
- {
- \
- if (word.find(' ', index) != -1)
- {
- length = word.find(' ', index);
- length -= index;
- LatWord = word.substr(index, length);
- LatWord.insert(length, "ay");
- LatWord.insert(length, 1, word[index]);//first letter is inserted at the end of the string
- LatWord.erase(0, 1);// erase first letter in string
- index += length + 1;//adding one moves index from 'space' to first letter in the next word
- }
- else
- {
- LatWord = word.substr(index);
- length = LatWord.length();
- LatWord.insert(length, "ay");
- LatWord.insert(length, 1, word[index]);
- LatWord.erase(0, 1);
- index = word.length();
- }
- LatSentence += (LatWord + " ");
- }
- return LatSentence;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement