string manipulation and condition


alright, i have enough of this string conditioning, just cannot get it right. Here is the function .

and there rule is .

i can handle the first vowel begins fine but the hardest part probably detect multiple consonants.



+++++++++++++++++++++++++++++++++++++++++

 For words which begin with a single consonant take the consonant off the front of the word and add it to the end of the word. Then add ay after the consonant. Here are some examples:

cat = atcay
dog = ogday
simply = implysay
noise = oisnay
For words which began with double or multiple consonants take the group of consonants off the front of the word and add them to the end, adding ay at the very end of the word. Here are some examples:

scratch = atchscray
thick = ickthay
flight = ightflay
grime = imegray

For words that begin with a vowel, just add yay at the end. For example:

is = isyay
apple =appleyay
under = underyay
octopus = octopusyay




+++++++++++++
void PigLatin::translator()

{
       string vowels = "aouie";
       string conso ="bcdfghjklmnpqrstvwxyz";
        vector <string>words;
  for (int i =0; i < num_of_words ; i++)
       
       {    words.push_back(result[i]);
            int word_length = result[i].size();
           
           
           for(int k = 0; k < vowels.size();k++)
             {
                 if ( words[i].at(0) == vowels.at(k)) //check if word begins vowel or not
             
                       result [i] = words[i] + "yay";
              }      
             
             
             
             
           
             for (int w =0; w < conso.size();w++)
             
                 {
                           
                 if (words[i].at(0) == conso.at(w))  //true if  consonant begins      
                     for (int z=0;z<vowels.size();z++)
                       if (words[i].at(1) == vowels.at(z))
                         result [i]= words[i].substr(1,word_length) + words[i].substr(0,1) + "ay";
                       
                        else //false if only 1 consonants
                            result [i]= words[i].substr(2,word_length) + words[i].substr(0,2) + "ay";
                           
                           
                   }
                   
         }
         
}
kevinngAsked:
Who is Participating?
 
PaulCaswellCommented:
Kevin,

You may find it easier to respecify the algorithm before implementing it. How about:

if ( starts with vowel )
{
 // Just add "yay"
}
else
{
 // Move all consonants at the start to the end.
 // Add "ay"
}

Since you are adding "ay" in both cases, you can recode this to:

if ( starts with vowel )
{
 // Just add "y" at end.
}
else
{
 // Move all consonants at the start to the end.
}

 // Add "ay" at end.

Now you can see a slight adjustment that makes coding simpler but slightly less efficient:

if ( starts with vowel )
{
 // Add "y" at end.
}

// Move all consonants at the start to the end.
// Add "ay" at end.

This, surely is easier to implement. Remember to write a separate function to detect whether a character is a vowel or a consonant. You might find
strchr ("aeiou", word[0]) != NULL
useful.

Paul
0
 
waysideCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: PaulCaswell

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

wayside
EE Cleanup Volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.