Write an application that encodes English language phrases into Pig Latin. Pig Latin is a form of coded language often used for amusement. Many variations exist in the methods used to form Pig Latin phrases. For simplicity, use the following algorithm: To translate each English word into a Pig Latin word, place the first letter of the English word at the end of the word and add the letters

“ay.” Thus, the word “jump” becomes “umpjay,” the word “the” becomes “hetay” and the word “computer” becomes “omputercay.” Blanks between words remain blanks. Assume the following: The English phrase consists of words separated by blanks, there are no punctuation marks and all words have two or more letters. Enable the user to input a sentence. Use a regex_token_iterator to divide the sentence into separate words. Function get- PigLatin should translate a single word into Pig Latin.

What will be an ideal response?


```
#include
#include
#include
using namespace std;

string getPigLatin( string );

int main()
{
string sentence, pigLatin;

// get the sentence from the user
cout << "Please enter a sentence: ";
getline( cin, sentence );

boost::sregex_token_iterator tokens( sentence.begin(), sentence.end(),
boost::regex( "\\s" ), -1 );
boost::sregex_token_iterator end;

while ( tokens != end )
{
pigLatin += getPigLatin( *tokens ) + " ";
++tokens;
} // end while

cout << pigLatin << endl;
} // end main

// translate a word into Pig Latin
string getPigLatin( string word )
{
// move the first letter at the end and add "ay"
word = word.substr( 1, word.size() - 1 ) + word[ 0 ] + "ay";
return word;
} // end function getPigLatin
```
Please enter a sentence: this is a sentence for translation
histay siay aay entencesay orfay ranslationtay

Computer Science & Information Technology

You might also like to view...

The conventional way to distinguish between the overloaded preincrement and postincrement operators (++) is:

a. To assign a dummy value to preincrement. b. To make the argument list of postincrement include an int. c. To have the postincrement operator call the preincrement operator. d. Implicitly done by the compiler.

Computer Science & Information Technology

Convert1710 to an 8-bit integer in sign-and-magnitude format:

a. 100012 b. 100100012 c. 000100012 d. 1100012

Computer Science & Information Technology

Answer the following statements true (T) or false (F)

1. A common type of secondary storage device is the solid state drive. 2. External disk drives can be used to create backup copies of important data or to move data to another computer. 3. The use of USB drives has declined dramatically in recent years in favor of superior devices such as floppy disk drives. 4. When Auto Hide is turned on, a window is displayed only as a tab along one of the edges of the Visual Studio environment.

Computer Science & Information Technology

What does the Compatibility Mode in the title bar indicate?

A) That the document has been saved in the Microsoft Word 2003 format B) The document to be automatically spell-checked C) The document to be automatically formatted D) That the document can be opened using Microsoft Access 2003

Computer Science & Information Technology