Question: Can someone add appropriate comments for this code? #include #include #include using namespace std; /** * */ bool isVowel(char ch); /** * Removes the first

Can someone add appropriate comments for this code?

#include #include #include using namespace std; /** * */ bool isVowel(char ch); /** * Removes the first character of the string, and places it at the * end of the string. * @param pString the word to be rotated. * @return the new reordered string */ string rotate(string pStr); /** * */ string pigLatinString(string pStr); int main() { string str; cout << "Enter a word: "; if (cin.peek() == ' ') { cin.ignore(1, ' '); }

getline(cin, str); cout << endl; // Output the text as pig Latin cout << "The pig Latin form of " << str << " is: " << pigLatinString(str) << endl; return 0; } bool isVowel(char ch) { switch (ch) { case 'A': case 'E': case 'I': case 'O': case 'U': case 'Y': case 'a': case 'e': case 'i': case 'o': case 'u': case 'y': return true; default: return false; } } string rotate(string pStr) { string::size_type len = pStr.length(); string rStr; rStr = pStr.substr(1, len - 1) + pStr[0]; return rStr; } string pigLatinString(string pStr) { string::size_type len; bool foundVowel; string::size_type counter; if (isVowel(pStr[0])) pStr = pStr + "-way"; else { pStr = pStr + '-'; pStr = rotate(pStr); len = pStr.length(); foundVowel = false; for (counter = 1; counter < len - 1; counter++) { if (isVowel(pStr[0])) { foundVowel = true; break; } else pStr = rotate(pStr); } if (!foundVowel) pStr = pStr.substr(1, len) + "-way"; else pStr = pStr + "ay"; } return pStr; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!