Skip to the content of the web site.

Project V.3: Pig latin

Author a function that takes as an argument a string, steps through the string, and prints the text in the following manner:

First requirement

  • For any word, take the first letter and print out the rest of the word, then that letter, and then the letters "ay".
  • All other characters are printed as is, and any non-letter character that appears after a letter signals the end of that word.

This is called pig latin.

For example, the "Hello world" program, entered as a single string, would be printed as follows:

#ncludeiay 

ntiay ainmay();

ntiay ainmay() {
    tdsay::outcay << "elloHay orldway!" << tdsay::ndleay;
    eturnray 0;
}

Second requirement

For slightly more of a challenge, maintain the capitalization of the word. For example, "Hello" is converted to "Ellohay" but "I" remains capitalized as "Iay".

Third requirement

  • If the word starts with up to three consonants, all three consonants are appended to the end followed by "ay".
  • If the word starts with up to three vowels, all vowels are moved to the end with a 'w' printed before the last vowel and all followed by a 'y'.

For example, "String" would be printed as "Ingstray" and "aardvark" would be printed as "rdvarkaway".