Computer Science, asked by shivajisingh0111, 6 months ago

wap in Java to accept a word and display the same in Piglatin form. sample input : TROUBLE sample output : OUBLETRAY.​

Answers

Answered by Anonymous
5

Answer:

// C++ program to encode a word to a Pig Latin.

#include <bits/stdc++.h>

using namespace std;

bool isVowel(char c)

{

return (c == 'A' || c == 'E' || c == 'I' ||

c == 'O' || c == 'U' || c == 'a' ||

c == 'e' || c == 'i' || c == 'o' ||

c == 'u');

}

string pigLatin(string s)

{

// the index of the first vowel is stored.

int len = s.length();

int index = -1;

for (int i = 0; i < len; i++) {

if (isVowel(s[i])) {

index = i;

break;

}

}

// Pig Latin is possible only if vowels

// is present

if (index == -1)

return "-1";

// Take all characters after index (including

// index). Append all characters which are before

// index. Finally append "ay"

return s.substr(index) + s.substr(0, index) + "ay";

}

// Driver code

int main()

{

string str = pigLatin("graphic");

if (str == "-1")

cout << "No vowels found. Pig Latin not possible";

else

cout << str;

}

Answered by atuljha275
4

Explanation:

Please like it and mark it as a brainlist if you liked it...Hope you loved it..

Attachments:
Similar questions