Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <sstream>
  4. #include <vector>
  5. #include <climits>
  6. #include <cctype>
  7. using namespace std;
  8.  
  9. void String(const string aLine, vector<string>& intermediate);
  10.  
  11. int main()
  12. {
  13. //starting up vars
  14. bool vowelConfirm = false;
  15. unsigned short i = 0, j = 0;
  16. string message = "";
  17. string interWord = "";
  18. string outputText = "";
  19. string yesno = "Y";
  20. string vowels = "aeiou";
  21. vector<string> intermediate;
  22. // loop to run as long as yesno is Y or y
  23. while(yesno == "Y" || yesno == "y")
  24. {
  25. outputText = "";
  26. intermediate.clear();
  27. //welcome message
  28. cout << "Welcome to the pig latin converter program!\n"
  29. << "Input word or phrase: \n";
  30. getline(cin, message);
  31. String(message, intermediate);
  32. vector<string>::iterator kitkat;
  33. for(i = 0, kitkat = intermediate.begin(); kitkat != intermediate.end(); i++, kitkat++)
  34. {
  35. string test = *kitkat;
  36. //tests for vowels at start
  37. vowelConfirm = false;
  38. if(test.length() < 2)
  39. {
  40. cerr << "The word " << test << " is too short!" << endl;
  41. }
  42. for(j = 0; j < vowels.length(); j++)
  43. {
  44. if(tolower(test[0]) == vowels[j])
  45. {
  46. vowelConfirm = true;
  47. interWord = test + "ay ";
  48. outputText += interWord;
  49. }
  50. }
  51. if(! vowelConfirm)
  52. {
  53. interWord = test.substr(1);
  54. interWord += test[0];
  55. interWord += "ay ";
  56. outputText += interWord;
  57. }
  58. }
  59. cout << "Your converted text is:\n"
  60. << outputText << endl;
  61. //reloop code
  62. cout << "Do you have another phrase to convert?(Y/N):";
  63. cin >> yesno;
  64. cin.ignore(INT_MAX, '\n');
  65. }
  66. //exit text
  67. cout << "Have a nice day! Exiting...\n";
  68. return 0;
  69. }
  70. //function for vec.push_back
  71. void String(const string aLine, vector<string>& intermediate)
  72. {
  73. string buffer;
  74. stringstream ss(aLine);
  75. while(ss >> buffer)
  76. {
  77. intermediate.push_back(buffer);
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement