Write a C++ Program to convert any given English Word into Pig Latin.
#include <bits/stdc++.h>
using namespace std;
bool CheckVowel(char Ch)
{
return (Ch == 'A' || Ch == 'E' || Ch == 'I' || Ch == 'O' || Ch == 'U' || Ch == 'a' || Ch == 'e' || Ch == 'i' || Ch == 'o' || Ch == 'u');
}
string PigLatin(string teststring)
{
int len = teststring.length();
int ind= -1;
for (int i = 0; i < len; i++) {
if (CheckVowel(teststring[i])) {
ind = i;
break;
}
}
if (ind == -1) return "-1";
return teststring.substr(ind) + teststring.substr(0, ind) + "ay";
}
int main()
{
string TestStr = PigLatin("PigLatin");
if (TestStr == "-1") cout << "\n\tNo vowels. Hence, Pig Latin not allowed.";
else cout << TestStr;
}
Comments
Leave a comment