I've been writing a pig latin translation program for a week in class now and i've gotten so far but now i don't know what to do.
i need to check if the word has a vowel as the first letter then only add ay in the end
if it has an "ay" sound ending i.e. has ay,ey,ai,ei at the end, then the word remains unchanged
i need to check if the word has one or more consonants in the beginning of it. if it does, the consonant need to go back of the word and then an "ay" needs to be added.
and i need to be able to do sentences. pls do not use advanced functions or new terms that i may not understand as i am still a student. my teacher told me to use the while loop and that finding the length of the string may help in some way.
here's the code i've done soo far.
#include <iostream>
#include <string>
using namespace std;
const string strVOWELS = "aeiouAEIOU";
const string strCONSONANTS = "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ";
const string strAYLIKEENDINGS = "ay","ei","ai","ey";
bool isAVowel(char);
bool isAConsonant(char);
bool hasAnAYLikeEnding(char);
void translateEnglishToLatin(string);
string strEnglish;
string strLatin;
int main()
{
cout << "Please enter stuff to be translated : ";
getline(cin,strEnglish);
translateEnglishToLatin(strEnglish);
cout << endl << "~~~~~~Translation~~~~~~" << endl << endl << strLatin << endl << endl;
return 0;
}
bool isAVowel(char ch)
{
return strVOWELS.find(ch) != string::npos;
}
bool isAConsonant(char ch)
{
return strCONSONANTS.find(ch) != string::npos;
}
bool hasAnAYLikeEnding(char ch)
{
return strAYLIKEENDINGS.find(ch) !=string::npos;
}
void translateEnglishToLatin (string strEnglish)
{
if(isAVowel(strEnglish[0]))
{
if(hasAnAYLikeEnding(strEnglish[-2 && -1]))
{
strLatin = strEnglish;
}
else
{
strLatin = strEnglish + "ay";
}
}
else
{
if(isAConsonant(strEnglish[0]) && isAVowel (strEnglish[1]))
{
strLatin = strEnglish.substr(1,strEnglish.length()-1) + strEnglish[0] + "ay";
}
else
{
int i1stVowel = 1;
while(! isAVowel(strEnglish[i1stVowel]))
i1stVowel++;
}
}
}