Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include<iostream> #include<string> using namespace std; bool isVowel ( char ch)

ID: 3620935 • Letter: #

Question

#include<iostream>
#include<string>
using namespace std;

bool isVowel ( char ch);
string rotate (string pStr);
string pigLatinString (string pStr);

int main () //function main begins execution
{
//declare variables
string phrase="";
string str ="";
size_t i ;

//let the user know about the program
cout << " Program that processes a text of an"
<< " unspecified lenght for Pig Latin Strings";

//prompt and read the imput from the user
cout << " Enter your choice of phrase: ";
getline (cin, phrase);

do
{
//find the index of a space in the phrase
i=phrase.find_first_of(" ");

//get the word from the phrase
str=phrase.substr(0,i);

//updated the phrase by removing the word
phrase=phrase.substr(i+1);

//print the word and its pig-latin-word
cout<<"n " << str <<" -- "
<< pigLatinString (str);
}while
(i ! = - 1); //end do-while

return 0;//indicate program executed successfully
}//end of function, main

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;
}//end of switch
}//end function isVowel

string rotate (string pStr)
{
//get the lenght of the string
string::size_type len = pStr.lenght ();

//rotate the word by moving the first letter to the last
string rStr=pStr.substr(1,len-1)+ pStr [0];

return rStr;
}//end function rotate

//returns the pig latin word for the given word
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.lenght ();
foundVowel=false;

for (counter = 1; counter<len-1;counter++)
if (isVowel ( pStr[0]))

foundVowel=true;
break;
}//end if
else
pStr = rotate (pStr);
if (!foundVowel)
pStr=pStr.substr(1,len)+"-way";
else
pStr = pStr + "ay";
}//end else-if
return pStr;
}//end function pigLatinString

Explanation / Answer

#include #include using namespace std; bool isVowel(char ch); string rotate(string pStr); string pigLatinString(string pStr); int main() { string str; cout > str; cout