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

The Programming Example: Pig Latin Strings converts a string into the pig Latin

ID: 3539484 • Letter: T

Question

The Programming Example: Pig Latin Strings converts a string into the pig

Latin form, but it processes only one word. Rewrite the program so that it

can be used to process a text of an unspecified length. If a word ends with a

punctuation mark, in the pig Latin form, put the punctuation at the end of

the string. For example, the pig Latin form of Hello! is ello-Hay!.

Assume that the text contains the following punctuation marks: , (comma),

. (period), ? (question mark), ; (semicolon), and : (colon).

source code:

#include <iostream>

#include <string>

using namespace std;

bool isVowel(char ch);

string rotate(string pStr);

string pigLatinString(string pStr);

int main()

{

string str;

cout << "Enter a string: ";

cin >> str;

cout << endl;

cout << "The pig Latin form of " << str << " is: "

<< pigLatinString(str) << endl;

system("pause");

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;

}


Explanation / Answer

please rate - thanks


tested using DEV C++

any questions/problems -ask, I will fix  

you weren't specific about some items




#include <iostream>

#include <string>

using namespace std;
bool isPunct(char ch);
bool isVowel(char ch);
string getWord(string,int&);
string rotate(string pStr);

string pigLatinString(string pStr);

int main()
{
string str;
cout << "Enter a string: ";
getline(cin,str);
cout << endl;
cout << "The pig Latin form of " << str << " is: "
<< pigLatinString(str) << endl;
system("pause");
return 0;
}
bool isPunct(char ch)
{
switch (ch)
{
case ',':
case '?':
case '.':
case ';':
case ':':
case '!':   
return true;
default:
return false;
}
}
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 getWord(string s,int& n)
{string out="";
int i;
for(;s[n]!=' '&&s[n]!='';n++)
     out=out+s[n];

n++;
return out;
       }
string pigLatinString(string str)
{string::size_type len;
bool foundVowel,done=false;
char c=' ';
string sentence="",pStr;
string::size_type counter;
int upto=0;
pStr = getWord(str,upto);
while (!(upto>str.length()+1))
{ if(isPunct(pStr[pStr.length()-1]))
       {c=pStr[pStr.length()-1];
       pStr[pStr.length()-1]='';
       }
   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";
}
sentence=sentence+" "+pStr;
if(!(upto>str.length()+1))
     pStr = getWord(str,upto);
}
    sentence=sentence+c;
return sentence;

}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote