(Pig Latin) Write a program 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 form a pig-Latin phrase from an English-language phrase, tokenize the phrase into words with function strtok. To translate each English
word into a pig-Latin word, place the first letter of the English word at the end of the English 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 as blanks. Assume that the English phrase consists of words separated by blanks, there are no punc- tuation marks and all words have two or more letters. Function printLatinWord should display each word. [Hint: Each time a token is found in a call to strtok, pass the token pointer to function printLatinWord and print the pig-Latin word.]
What will be an ideal response?
```
#include
#include
using namespace std;
const int SIZE = 80;
// function prototype
void printLatinWord( char const * const );
int main()
{
char sentence[ SIZE ];
char *tokenPtr;
cout << "Enter a sentence:\n";
cin.getline( sentence, SIZE ); // read in, but only up to 80 characters
cout << "\nThe sentence in Pig Latin is:\n";
// call function strtok to alter the sentence
tokenPtr = strtok( sentence, " .,;" );
// if there is still word in tokenPtr
while ( tokenPtr )
{
printLatinWord( tokenPtr );
tokenPtr = strtok( 0, " .,;" );
if ( tokenPtr )
cout << ' ';
} // end while
cout << '.' << endl;
return 0;
} // end main
// print out the English word in Pig Latin form
void printLatinWord( char const * const wordPtr )
{
int len = strlen( wordPtr );
// loop through the word
for (int i = 1; i < len; i++ )
cout << *( wordPtr + i );
cout << *wordPtr << "ay";
} // end printLatinWord
```
Enter a sentence:
mirror mirror on the wall
The sentence in Pig Latin is:
irrormay irrormay noay hetay allway.
You might also like to view...
What is another name for the notification area in Windows?
A. system tray B. taskbar C. Control Panel D. Start Menu
The third line of a header in multiple page letters and memos contain the ____________________ .
Fill in the blank(s) with the appropriate word(s).
The ALE is calculated by multiplying the SLE by the ____________________.
Fill in the blank(s) with the appropriate word(s).
You need to create Internet access for customers while onsite. You need to prevent the customers from accessing any corporate data. What can you do?
A. configure a guest wireless network B. implement a DMZ C. disable NAT on the wireless network D. assign static IPs for all devices