Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5.  
  6. // takes a string and converts it to pig latin
  7. string Latin(string);
  8.  
  9. int main()
  10. {
  11. cout<< "enter your statement that you want to translate"<<endl;
  12. string mySentence;
  13.  
  14. getline(cin, mySentence);
  15. mySentence = Latin(mySentence);
  16. cout << mySentence << endl;
  17.  
  18. return 0;
  19. }
  20.  
  21. string Latin(string word)
  22. {
  23.  
  24.  
  25. string LatWord, LatSentence = "";
  26. int length = 0, index = 0;
  27.  
  28. while (word[index] != '\0')
  29. {
  30. \
  31. if (word.find(' ', index) != -1)
  32. {
  33. length = word.find(' ', index);
  34. length -= index;
  35. LatWord = word.substr(index, length);
  36. LatWord.insert(length, "ay");
  37. LatWord.insert(length, 1, word[index]);//first letter is inserted at the end of the string
  38. LatWord.erase(0, 1);// erase first letter in string
  39. index += length + 1;//adding one moves index from 'space' to first letter in the next word
  40. }
  41. else
  42. {
  43. LatWord = word.substr(index);
  44. length = LatWord.length();
  45. LatWord.insert(length, "ay");
  46. LatWord.insert(length, 1, word[index]);
  47. LatWord.erase(0, 1);
  48. index = word.length();
  49. }
  50.  
  51. LatSentence += (LatWord + " ");
  52. }
  53. return LatSentence;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement