Write a C++ program for .... (Pig Latin) A language game, such as Pig Latin, alt
ID: 3667361 • Letter: W
Question
Write a C++ program for .... (Pig Latin) A language game, such as Pig Latin, alters spoken words to make them incomprehensible to the untrained ear. Write a program to prompt the user for an English word, phrase, or sentence and then translate the words into Pig Latin, as follows: the initial consonants are moved from the front of the word to the end and the letters “ay” are then added to the end. Thus “meal” becomes “eal-may”, “scram” becomes “am-scray”, and “java” becomes “ava-jay”. If the word begins with a vowel, then just add “ay” to the end.
If you could add comments to the code, explaining whats going on, it would be appreciated!
Explanation / Answer
hi !
Explanation for Pig Latin Translator in C++
The program will use two character arrays, namely english, piglatin. first word containing the original message, and the other containing the translated Pig Latin word. Overall word matching formula of the Pig Latin Translator is simple and straightforward; The following steps:
Source code starts from here:
#include <iomanip>
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
string pigLatinString(string);
const int size = 80; //Each text message can be typed on one 80-column line only, with a single black space between each words.
string strEnglish[size];
int main()
{
cout << endl << endl;
cout << "***This program A language game, such as Pig Latin, alters spoken words to make them incomprehensible to the untrained ear ***" << endl;
cout << "*** Those words (The string) will be converted into Pig Latin and the results displayed. ***" << endl;
cout << "*** Enter as many WORDS as you would like. ***" << endl << endl;
while (true)
{
cout << "Enter a group of words or ENTER to quit: ";
getline (cin, strEnglish[size] ); // This will get your words from User to Program
cout << endl << endl;
if ( strEnglish[size].length() == 0) // If condition to check whether User entered word or only empty space
break;
cout << "Original words: " << strEnglish[size]; // the given orginal words enter by user
cout << endl << endl;
cout << "New words: " << pigLatinString(strEnglish[size]); // to display the output , a subprogram called here
cout << endl << endl;
}
return 0;
}
// a sub program for pigLatin ///////////
string pigLatinString(string strTran) // a sub program to change to engligh word into Pig latin
{
string::size_type start = 0;
string::size_type begin = 0;
string word;
string strLatin = "";
while(true)
{
start = strTran.find(' ', start);
if(start == string::npos)
break;
word = strTran.substr(begin, start - begin);
strLatin += word.substr(1) + word.substr(0, 1) + "ay"; // here instead of "ay" , you can ddd anything. Example "a"
start++;
begin = start;
}
return strLatin;
}
/* OUTPUT
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.