Answer to Question #257987 in C++ for ace

Question #257987

Write a C++ Program to convert any given English Word into Pig Latin.


1
Expert's answer
2021-10-28T05:22:26-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS