Below is the C++ code I hope that i have provided sufficient comments for your better understanding Note that I have done proper indentation but this code is automatically left alligned on this interface
#include <iostream>
#include <string>
using namespace std;
// Prototypes
string leftTrim(string);
string popWord(string &);
string toPigLatin(string);
int main()
{
// Declare 3 strings
// To hold the user's input
// To hold the translated string
// to hold a word
string str,piglatin="",word;
// Get a sentence from the user.
cout<<"English:";
getline(cin,str);
// Translate each word and create a new string.
while (str.size() > 0)
{
// Get the next word from the string by caaling popWord.
word=popWord(str);
// Translate the word to Pig Latin by calling toPigLatin
function.
word=toPigLatin(word);
// Add the word and a space to the pig string.
piglatin+=word+" ";
}
// Display the translated string
cout<<"Pig Latin:"<<piglatin;
return 0;
}
// The leftTrim function accepts a string
// argument and returns that same argument
// with any leading spaces removed.
//
string leftTrim(string str)
{
while(str.front()==' ')
str.erase(str.begin()); //remove 1st character that is space
return str;
}
// The popWord function accepts a string argument,
// passed by reference. It removes the first word
// from the string and then returns that word.
string popWord(string &sentence)
{
// Trim any spaces from the beginning of the string.
sentence=leftTrim(sentence);
// Locate the first space, or the end of the string.
int ind=sentence.find(' ');
// Copy the substring from the beginning of sentence
// up to index, and store the copy in word.
string word;
if(ind==-1)
{
//we reached end of string hence consider complete word
word=sentence;
}
else
{
word=sentence.substr(0,ind);
}
// Remove the word from sentence.
if(ind==-1)
{
sentence.clear();
}
else
{
sentence.erase(sentence.begin(),sentence.begin()+ind);
}
// Return the extracted word.
return word;
}
// The toPigLatin function accepts a string
// containing a word. It returns that word
// translated to Pig Latin.
string toPigLatin(string word)
{
// Get the first letter of the word.
char ch=word[0];
// Append the letter to the end of the word.
word.push_back(ch);
// Append "ay" to the word.
word.append("AY");
// Delete the first letter.
word.erase(word.begin());
// Return the word.
return word;
}
use C++ Pig Latin Background Pig latin is a "language” where you take the regular English...
Please use PYTHON3 to Create a program that translates English into Pig Latin. The function will take the first letter of each word in the sentence only if it’s a not a vowel, and place it at the end of the word followed by “ay”. Your program must be case insensitive. You must write the function translate() that takes in a single English word and returns its Pig Latin translation. Remember translate must take only one word as input. #############################################################...
JAVA PROGRAMMING LANGUAGE!!!! Pig Latin Write a program that reads a sentence as input and converts each word to "Pig Latin". In one version of Pig Latin, you convert a word by removing the first letter, placing that letter at the end of the word, and then appending "ay" to the word. Here is an example: English: I SLEPT MOST OF THE NIGHT Pig Latin : TAY LEPTSAY OSTMAY FOÀY HETAY 1GHTNAY make sure that there are two...
In C
Sixth: Pig Latin (10 Points) For this part of the assignment, you will need to write a program that reads an input string representing a sentence, and convert it into pig latin. We'll be using two simple rules of pig latin: 1. If the word begins with a consonant then take all the letters up until the first vowel and put them at the end and then add "ay" at the end. 2. If the word begins with...
Assignment 5 Due Apr 5 by 11:59pm Points 100 Submitting a file upload A5 Wrapper Classes "Pig Latin" Access A5 from pdf assigament file t Turn in the following files aSmain java program compile and run screenshots design document AS 15. Pig Latin Write a program that reads a sentence as input and converts each word to "Pig Latin". In one version of Pig Latin, you convert a word by removing the first letter, placing that letter at the end...
Write a program that prompts the user to input a string and then outputs the string in the pig Latin form. The rules for converting a string into pig Latin form are asfollows:a. If the string begins with a vowel, add the string "-way" at the end of the string. for example, the pig Latin form of the string "eye" is "eye-way".b. If the string does not begin with a vowel, first ass "-" at the end of the string....
In C please
Pig latin has two very simple rules:
If a word starts with a consonant move the first letter(s) of
the word, till you reach a vowel, to the end of the word and add
"ay" to the end.
have ➞ avehay
cram ➞ amcray
take ➞ aketay
cat ➞ atcay
shrimp ➞ impshray
trebuchet ➞ ebuchettray
If a word starts with a vowel add "yay" to the end of the word.
ate ➞ ateyay
apple ➞ appleyay...
There is a children's "secret language" called "Pig Latin" which supposedly allows conversation the uninformed (such as parents) cannot understand. The rules are: If a word begins with a vowel (aeiou) then append "way" to the word. For example, "Aggie" becomes "Aggieway". Otherwise, remove the consecutive non-vowels from the beginning of the word, append them to the end of the word, and append "ay" to the word. For example, "whoop" becomes "oopwhay". Write a program named hw5pr1.cpp which reads words...
Design and code a SWING GUI to translate text entered in English into Pig Latin. You can assume that the sentence contains no punctuation. The rules for Pig Latin are as follows: For words that begin with consonants, move the leading consonant to the end of the word and add “ay”. Thus, “ball” becomes “allbay”; “button” becomes “uttonbay”; and so forth. For words that begin with vowels, add “way’ to the end of the word. Thus, “all” becomes “allway”; “one”...
Correct the syntax errors to allow the code to pass all of the
provided doctests.
You may have heard of "Pig Latin," a set of rules for modifying regular English to render it unintelligible to those who do not know the rules. This problem asks you to fix a function that will convert an English word to Pig Latin The rules for converting a word to Pig Latin are as follows: 1. If the word starts with a vowel, add...
Pig Latin Translator in Java The goal here is to read in the characters stored in a text file and create a second text file that contains the original text but with every word converted to “Pig-Latin.” The rules used by Pig Latin are as follows: • If a word begins with a vowel, just as "yay" to the end. For example, "out" is translated into "outyay". • If it begins with a consonant, then we take all consonants before...