Structured Programming in C++
Prof. Gregory Safko

Camden County College, Cherry Hill Campus

Project 2

 

Assigned: April 9, 2004

Due: May 7, 2004

 


 

Pig-Latin Processor 

 

 

Write a program (Project2.cpp) that will ask the user for a word, and will return its representation in Pig Latin.

 

As a brief primer, to convert a word into Pig Latin, you take the first letter of the word, move it to the end of the word, and add “ay” to the end.

 

You code will work in the following way:

 

Enter a word: College

In Pig Latin: ollegecay

 

(Notice the uppercase and lowercase differences between the entered word, and the Pig Latin word)

 

There are rules to Pig Latin, however. They are as follows:

 

 

1. If the word begins with more than one consonant, move all those consonants (until you reach a vowel) to the end, and then add “ay” as before.

 

Another sample run (based on the preceding rule)

 

Enter a word: Friday

In Pig Latin: idayfray

 

Yet another sample run (based on the preceding rule)

 

Enter a word: strong

In Pig Latin: ongstray

 

 

2. Another rule in Pig Latin deals with words that begin with vowels. If a word begins with a vowel, just add “yay” to the end (If the word already ends in 'y', just add "ay" to the end)

 

A sample run (based on the preceding rule)

 

Enter a word: October

In Pig Latin: octoberyay

 

Another sample run (based on the preceding rule)

 

Enter a word: oily

In Pig Latin: oilyay

 

3. If a word has no vowels, just add “yay” to the end. If the word already ends in ‘y’, just add ‘ay’ at the end. (As a reminder, for Pig Latin, the letter ‘y’ is not considered a vowel)

 

A sample run (based on the preceding rule)

 

 

Enter a word: Rhythm

In Pig Latin: rhythmyay

 

 

Another sample run (based on the preceding rule)

 

Enter a word: sly

In Pig Latin: slyay

 

 

4. If a word begins with a ‘q’ (or contains a ‘q’ before a vowels is found), then the following letter is most likely a ‘u’, so remove the “qu” (and any additional letters that precede the “qu”), move them to the end, and “ay” to the end

 

A sample run (based on the preceding rule)

 

Enter a word: quick

In Pig Latin: ickquay

 

Another sample run (based on the preceding rule)

 

Enter a word: squid

In Pig Latin: idsquay

 

 

Some hints and rules:

 

  1. Code will be appropriately documented, formatted, and indented.
  2. Send all words to be tested to a makePigLatin( ) function
  3. All words returned by the makePigLatin( ) function will be in lowercase.
  4. You may want to write a findVowel( ) functions (based on your countVowel( ) function from a previous lab) to assist in locating a vowel.
  5. You can write any “helper” functions that you wish to accomplish the task

 

Assumptions:

  1. Assume that no numbers will be entered in the input stream.
  2. Assume that no punctuation will be entered in the input stream.
  3. Assume that the user will enter something to be tested (i.e. no empty strings will be sent to the program)

 

Submission Requirements

  1. First preference: email: Must be submitted by 11:59PM that night as an attachment file (no source code embedded in the body of the mail, please!). The source code file will be named project2.cpp.
  2. Second preference: diskette: Must be submitted by normal end-of-class time. The source code file will be named project2.cpp.
  3. Third preference (least preference): A Hardcopy printout of the project. Must be submitted by normal end-of-class time.
  4. Make sure you place your teammates names in the comment area of the code.
  5. Deduct 15 points for single submissions (i.e. submission without teammates)

 

 

PIG LATIN RULES

Although many sites and source have variations on the rules of Pig Latin, the following are used for this project:

 

·         For words that begin with a vowel, just add 'yay' to the end of the word. (if the word ends in a ‘y’, just add ‘ay’)

·         For words that have no vowels, just add ‘yay” (if the word ends in a ‘y’, just add ‘ay’)

·         For words that begin with a consonant, put the consonant at the end of the word, and add 'ay' on the end of that.

·         For words that begin with two or more consonants, put them at the end of the word and add 'ay'.

·         For words that begin with a ‘qu’, move the qu to the end and add ‘ay’