Try the fastest way to create flashcards

Related questions with answers

Question

(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

Verified
Answered 1 year ago
Answered 1 year ago
Step 1
1 of 5

First, 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 by Ramez Elmasri, Shamkant B. Navathe

Fundamentals of Database Systems

7th EditionISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
948 solutions
C: How to Program 6th Edition by Harvey M. Deitel, Paul J. Deitel

C: How to Program

6th EditionISBN: 9780136123569Harvey M. Deitel, Paul J. Deitel
449 solutions
Introduction to Algorithms 3rd Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

3rd EditionISBN: 9780262033848Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
872 solutions
Introduction to Algorithms 4th Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

4th EditionISBN: 9780262046305Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
945 solutions

More related questions

1/4

1/7