Hey everyone. I am trying to get a program working to convert an English sentence into a pig latin sentence. I don't have much right now but I have little to go off of or direction. Please help!
okay so now i have a little more after a few hours haha but i don't know how to go about checking if the next char is a vowel or constant then how to move that to the end. any help is greatly appreciated!!!!
#include<iostream> //need to: remove period and constant starting words aren't working(the constant is cut
//off in the beginning then disappears). the constant should be thrown onto the end of the word then ay
//added. also have to include qu thing and if the word ends in y.
//words starting with a vowel do just fine
#include<string>
#include<vector>
usingnamespace std;
bool is_vowel(string c);
bool is_vowel_char(char c);
short check_for_const(string a);
string translate(string & a);
short check_for_vowel(string a);
string remove_period(string & a);
int main(void)
{
cout << "\n\n\t\tWelcome to the Pig Lating Program!";
vector<string> phrase;
cout << "\n\nPlease enter your phrase (end with a period): ";
bool more = true;
do
{
string word;
cin >> word;
phrase.push_back(word);
if( word[word.length()-1] == '.')
{
more = false;
}
} while(more);
//phrase.pop_back();
//(phrase[phrase.size()-1]).replace(phrase[phrase.size()-1].length()-1, ""); //trying to replace the period with ""
//remove_period( phrase.size()-1); //another attempt to remove the period
for( vector<short>::size_type i = 0; i <= ( phrase.size() - 1 ); i++)
{
if( is_vowel( phrase[i] ) ) //if the word starts with a vowel
{
phrase[i] += "yay";
}
else
{
phrase[i] = translate(phrase[i]);//put in translate func here for words that start with constant
}
}
for( vector<short>::size_type phrase_pos = 0; phrase_pos != (phrase.size() - 1); phrase_pos++)
{
cout << phrase[phrase_pos] << ' ';
}
cout << phrase.back();
return 0;
}
bool is_vowel(string c)
{
char b = tolower(c[0]);
return b == 'a' || b == 'e' || b == 'i' || b == 'o' || b == 'u';
}
bool is_vowel_char(char c)
{
return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}
short check_for_const(string a)
{
short pos;
for( vector<short>::size_type i = 0; i <= a.size() - 1; i++)
{
if( !is_vowel_char( a[i] ))
{
pos = i;
}
}
return pos;
}
short check_for_vowel(string a)
{
short pos;
for( vector<short>::size_type i = 0; i <= a.size() - 1; i++)
{
if( is_vowel_char( a[i] ))
{
pos = i;
i = a.size();
}
}
return pos;
}
string translate(string & a)
{
string b;
string c;
short vowel_pos = check_for_vowel(a);
b = a.substr(0, vowel_pos-1);
a = a.substr( vowel_pos, a.size() - 1);
c = a + b + "ay";
return c;
}
/*
string remove_period(string & a)
{
a.erase(a.length-1, 1);
//(phrase[phrase.size()-1]).replace(phrase[phrase.size()-1].length()-1, "")
return a;
}
*/