+ 2

How can i write a code to convert a sentence in PigLatin language ?

it must allow user to enter input. also user must be able to enter a sentence.

22nd Jul 2020, 3:16 PM
Calvin Hubert
Calvin Hubert - avatar
3 Respuestas
+ 1
This is code to my question but in adivice some of mobile devices will fail to compile this code #include <iostream> #include<string> using namespace std; string leftTrim(string); string getWord(string); string toPigLatin(string); int main() { string str; string piglatin; cout<<"Please Enter a sentence that you want translate into pig Latin.\n"; getline(cin,str); while(str.size() >0){ string word = getWord(str); word =toPigLatin(word); piglatin = piglatin + word + " "; } cout<<piglatin<<endl; getchar(); return 0; } string trim(string str) { while(str[0]==' '){ str.erase(0,1); } return str; } string getWord(string &str){ str = trim(str); int index =0; while (str[index] != ' '&& index < str.size()) index++; string word =str.substr(0,index); str.erase(0,index); return word; string toPigLatin (string word){ char first = word[0]; word.append(1,first); word.append("ay"); word.erase(0,1); return word; }
22nd Jul 2020, 3:56 PM
Calvin Hubert
Calvin Hubert - avatar
+ 1
Better will be to save the code on the Playground and link here.
22nd Jul 2020, 5:00 PM
JaScript
JaScript - avatar
23rd Jul 2020, 1:31 PM
shubham kumar
shubham kumar - avatar