Related questions with answers
(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 the following: The English phrase consists of words separated by blanks, there are no punctuation marks, and all words have two or more letters. Function print Latin Word should display each word. [Hint: Each time a token is found in a call to strtok, pass the token pointer to function print Latin Word, and print the pig-Latin word. Note: We’ve provided simplified rules for converting words to Pig Latin here. For more detailed rules and variations, visit en.wikipedia.org/wiki/Pig latin.]
Solution
VerifiedFirst, let's think for a minute about what the main program will look like. We start by declaring the variables, and then by prompting the user to enter a sentence. Then, we tokenize the given string with the help of a strtok function, and use the while loop in a combination with the pointer to the tokens, so that we can call the function for printing pig latin words for every word given in the sentence. The pseudocode might look like this:
getTheString()
tokenizeTheString()
while (pointer points to the string token)
printPigLatinWord(string token)
moveThePointerToTheNextStringToken()
Create a free account to view solutions
Create a free account to view solutions
Recommended textbook solutions

Fundamentals of Database Systems
7th Edition•ISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe

Introduction to Algorithms
3rd Edition•ISBN: 9780262033848Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
Introduction to Algorithms
4th Edition•ISBN: 9780262046305Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. CormenMore related questions
1/4
1/7