Difference between revisions of "Pig Latin Translator"

From WLCS
Line 12: Line 12:
 
'''Directions:'''
 
'''Directions:'''
 
# Your first task is to produce a function named getPrefix(s) that takes one '''argument''', a string, and '''returns''' the portion of the word up to, but not including the first vowel. For example, if you sent 'banana' to your function, it should '''return''' 'b'. Sending 'Sibley' should return 'S', 'stream' should return 'str', and 'break' should return 'br'. Print out your working function and a sample run.
 
# Your first task is to produce a function named getPrefix(s) that takes one '''argument''', a string, and '''returns''' the portion of the word up to, but not including the first vowel. For example, if you sent 'banana' to your function, it should '''return''' 'b'. Sending 'Sibley' should return 'S', 'stream' should return 'str', and 'break' should return 'br'. Print out your working function and a sample run.
 
 
# Your next task is to produce a function named getStem(s) that takes one '''argument''', a string, and '''returns''' the stem portion of the word including the first vowel.
 
# Your next task is to produce a function named getStem(s) that takes one '''argument''', a string, and '''returns''' the stem portion of the word including the first vowel.
 
 
# Create a function named translateWord(s) that takes one '''argument''', a string, and function calls to getPrefix(s) and getStem(s) to return the Pig Latin translated word.  You should also be sure that you follow the rules of Pig Latin listed above (e.g. If the word contains no consonants, just add yay)
 
# Create a function named translateWord(s) that takes one '''argument''', a string, and function calls to getPrefix(s) and getStem(s) to return the Pig Latin translated word.  You should also be sure that you follow the rules of Pig Latin listed above (e.g. If the word contains no consonants, just add yay)
  

Revision as of 15:16, 5 January 2009

Objective:

  • You will create a program that translates English to Pig Latin

Translation Rules:

  1. If a word has no letters, don't translate it.
  2. All punctuation should be preserved.
  3. If the word begins with a capital letter, then the translated word should too.
  4. Separate each word into two parts. The first part is called the prefix and extends from the beginning of the word up to, but not including, the first vowel. (The letter y will be considered a vowel.) The rest of the word is called the stem.
  5. The Pig Latin text is formed by reversing the order of the prefix and stem and adding the letters ay to the end. For example, sandwich is composed of s + andwich + ay + . and would translate to andwichsay.
  6. If the word contains no consonants, let the prefix be empty and the word be the stem. The word ending should be yay instead of merely ay. For example, I would be Iyay.

Directions:

  1. Your first task is to produce a function named getPrefix(s) that takes one argument, a string, and returns the portion of the word up to, but not including the first vowel. For example, if you sent 'banana' to your function, it should return 'b'. Sending 'Sibley' should return 'S', 'stream' should return 'str', and 'break' should return 'br'. Print out your working function and a sample run.
  2. Your next task is to produce a function named getStem(s) that takes one argument, a string, and returns the stem portion of the word including the first vowel.
  3. Create a function named translateWord(s) that takes one argument, a string, and function calls to getPrefix(s) and getStem(s) to return the Pig Latin translated word. You should also be sure that you follow the rules of Pig Latin listed above (e.g. If the word contains no consonants, just add yay)

Examples:

--> stop
opstay
--> littering
itteringlay
--> buddy
uddybay