CSCI 116 Programming Project #11

Arrays and Strings—Pig Latin

 

Purpose: To begin working with arrays and strings, to write a program that is more than 20 lines long, and to get more practice with functional abstraction (as well as to write a really cool Pig Latin translator).

 

Assignment:  You are to write a program that translates English to Pig Latin.  In case you have forgotten, the way you translate English to Pig Latin is to use the following rules:

  1. If the word starts with a vowel (A, E, I, O, U), append the string way to the word.
  2. If the word starts with one or more consonants, move all the consonants preceding the first vowel to the end of the word, and append the string ay.
  3. If the word starts with qu, move both the q and the u to the end of the word before appending ay.
  4. If the letter y occurs inside a word, consider it a vowel.  If it is the initial letter of a word, consider it a consonant.
  5. Numbers, punctuation, etc, are passed through unchanged.

Here are some examples:

  • after  becomes afterway
  • plunger  becomes ungerplay
  • quiet  becomes ietquay
  • yellow  becomes ellowyay
  • style  becomes ylestay
  • 123abc  becomes 123abc

Your program should prompt the user to enter a sentence.  It should read that sentence into an array, and echo the sentence back again.  It should then translate the sentence to Pig Latin and print out the resulting translation.  This process should then repeat.  To terminate the program the user should type the word exit, using any type of capitalization.

Here is a sample run:

 

Pig Latin translation program

Enter a sentence to translate to Pig Latin (“exit” to quit):

Help, I’m being held prisoner in a Chinese fortune cookie factory.

The sentence:

Help, I’m being held prisoner in a Chinese fortune cookie factory.

translates to Pig Latin as:

Elphay, I’mway eingbay eldhay isonerpray inway away Inesechay ortunefay ookiecay actoryfay.

Enter a sentence to translate to Pig Latin (“exit” to quit):

Exit

Exitingway...ankthay ouyay orfay usingway isthay ogrampray.

 

Programming Style: Your program should follow all the style guidelines given in the first programming assignment.

 

Getting Started: To get started, get the I/O working first, so your program reads a sentence into an array, prints it out again, and exits at the right time.  Then work on your Pig Latin translator.  You might want to take advantage of some of the character functions we’ve discussed before, such as tolower, isalpha, and so on.

 

Turn in: You should turn in a listing of your program, with the output it generates for a sample run included as comments at the end of the source file.

 

Background: For those of you who might be wondering, here is a history of Pig Latin.  I knew it was authoritative since I found it on the web! J

Most definitely, Pig Latin is a language in and of itself. It was used in southern Europe from around 1200 BC to perhaps AD 500, coming into prominence after the collapse of the Graeco-Pork empire around 300 BC. Pig Greek had dominated until then, naturally. Both Pig Latin and Pig Greek are members of the Pig Indo-European language family, and share many cognates, significantly in fundamental words like mother (atermay), father (aterpay), and mouse (usmay), to name just a few. Pig Greek, in which the early Porcine scriptures were written, survives to this day, although with quite a few changes, as with Greek. The Pig Greek Digamma letter F (effay) has been dropped in favor of the letter Phi (ephay), and the Pig Attic dialectic variations have all but disappeared. So the Pig Greek spelling of the word for sea (allassothay) is almost never seen in its Attic form (allattothay) anymore. Sadly, Pig Latin has all but died out, although it has left quite a swine legacy in Pig Italian.  Wayne Baisley(?)