Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions

Question

Have roles been defined and assigned?

Answered: 1 week ago

Question

Are these written ground rules?

Answered: 1 week ago

Question

How do members envision the ideal team?

Answered: 1 week ago