How to add ub before each vowel in c++?

Hello, I am writing a program that need to translate in ubbi dbbi translator.

However, I am not sure how to write the code to add ub before each vowel for a word

I know it is kinda similar to pig latin and I tried that but pig latin adds ay at the end and this is different.

Please help


bool is_vowel(char ch)
{
return (ch =='A' || ch =='E' || ch =='I'|| ch =='0'|| ch =='U'
|| ch =='a' || ch =='e' || ch =='i'|| ch =='o'|| ch =='u');

}
string translate_to_pig_latin(string str)
{
string translated;

if (contains_only_letters(str))
{

if (is_vowel(str.at(0)))
translated = str + "way";
else
translated = str.substr(1,str.length()-1) + str.at(0) + "ay";
}
else
translated = str;

return translated;



}

ิhow can I change to ub
Last edited on
Find a vowel in a string. Insert "ub" before it.

Perhaps you should start with the finding part.
perhaps bool contains_only_letters(string str)
{
for (int i = 0; i < str.length() ; i++)

if ( (str.at(i) <'a' || str.at(i) >'z') && (str.at(i) <'A' || str.at(i) >'Z'))
return false;


return true;

}

bool is_vowel(char ch)
{
return (ch =='A' || ch =='E' || ch =='I'|| ch =='0'|| ch =='U'
|| ch =='a' || ch =='e' || ch =='i'|| ch =='o'|| ch =='u');

}

string translate_to_pig_latin(string str)
{
string translated;

if (contains_only_letters(str))
{

if (is_vowel(str)
translated = ub
else
translated= str;
}
else
translated = str;

return translated;



}
Since you don't seem to understand the pig-latin code, I suggest you trash it and start from scratch.
I understand the pig latin code but I don't understand how to add ub before each vowel.
You seem to have the code down pretty pat. Looking at it, you already have the search function. All that needs to be done (depending on how you view your code) is either have your function add "ub" to the spot where you found the vowel, or (more likely scenario) go back 1 index and add "ub".

I only say this because when you append strings together, the one you're adding on gets tacked on at the end.


Also looking at some other posts, someone seems to have gotten their jimmies severely rustled.
Topic archived. No new replies allowed.