% Function Name: pigLatinPhrase % Inputs (1): - (char) A word or phrase to be tr
ID: 3645145 • Letter: #
Question
% Function Name: pigLatinPhrase% Inputs (1): - (char) A word or phrase to be translated into Pig Latin
% Outputs (1): - (char) The translated word or phrase
%
% Function Description:
% Pig Latin is a language game of word alterations that has existed in
% some form since the late 1800s. Modern Pig Latin is a simple encodement
% of words created by rearranging and adding specific syllables to the
% end of English words. Write a function called "pigLatin" that takes in
% a string containing a word or phrase and returns the same string
% translated into Pig Latin.
%
% The rules for translating into Pig Latin are as follows:
%
% 1. In words that begin with a consonant sound, the initial consonant or
% group of consonants is moved to the end of the word, and the syllable
% "ay" is added. A hyphen is placed before the moved consonants for
% clarity in transcribing back to English.
% e.g. "computer" -> "omputer-cay", "stranded" -> "anded-stray"
%
% 2. In words that begin with a vowel, the syllable "way" is added to the
% end of the word and is preceded by a hyphen.
% e.g. "almond" -> "almond-way", "under" -> "under-way"
%
% Notes:
% - The input string may be a single word or a phrase containing
% several words separated by spaces.
% - The input string is guaranteed to contain only lowercase letters.
% - the words in the phrase will be separated by a single space and
% there will not be any other characters besides lowercase letters
% (puncuation, etc).
%
% Hints:
% - You may find your pigLatin() function from HW03 useful. If you use
% it, be sure to include your pigLatin.m with the rest of your submission
% files.
%
% Test Cases:
% out1 = pigLatinPhrase('elephant')
% out1 => 'elephant-way'
%
% out2 = pigLatinPhrase('the breakfast of champions')
% out2 => 'e-thay eakfast-bray of-way ampions-chay'
%
% out3 = pigLatinPhrase('you had me at hello world')
% out3 => 'ou-yay ad-hay e-may at-way ello-hay orld-way'
%
Explanation / Answer
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 "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 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.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.