Question

In: Computer Science

C++ Project 6-2: Pig Latin Translator Create a program that translates English to Pig Latin. Console...

C++

Project 6-2: Pig Latin Translator

Create a program that translates English to Pig Latin.

Console

Pig Latin Translator

This program translates a sentence

and removes all punctuation from it.

Enter a sentence: 'Tis but a scratch.

Translation:      Istay utbay away atchscray

Specifications

  • Convert the English to lowercase before translating.
  • Remove all punctuation characters before translating.
  • Assume that words are separated from each other by a single space.
  • If the word starts with a vowel, just add way to the end of the word.
  • If the word starts with a consonant, move all of the consonants that appear before the first vowel to the end of the word, then add ay to the end of the word.
  • If a word starts with the letter y, the y should be treated as a consonant. If the y appears anywhere else in the word, it should be treated as a vowel.

Note

  • There are no official rules for Pig Latin. Most people agree on how words that begin with consonants are translated, but there are many different ways to handle words that begin with vowels.

Solutions

Expert Solution

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

#include <string>
#include <iostream>
#include<cstdlib>
using namespace std;

int flag=1;
///////////////////////////////////////////////////////////////////////
///////////////////////FUNCTION LIST///////////////////////////////////////////////
bool isVowels(char x);
void Vowel(string changed);
void nonVowel(char begin, string end);
void changeLine (string line);
void printHeader();

////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
////////////////////BEGIN THE MAIN PROGRAM///////////////////////////////////////////


int main()
{

char ch;
string word, first, line;


getline(cin,line);//input a line of words
cout <<endl;
string nLine="";
for(int i=0;i<line.length();i++)
{
if(!ispunct(line[i]))
nLine=nLine+line[i];
}
changeLine(nLine);// output of the new sentence in Pig Latin

return 0;
}
/////////////////////////////////////////////////////////////////////////////////
////////////////////////////END OF MAIN//////////////////////////////////////////


bool isVowels(char x) // this is where all of the vowels in the words are found. It will
//read in the word, change the letter to loower case.
{
char low_case = tolower (x);
if (low_case == 'a' )
return true;
else if (low_case == 'e' )
return true;
else if ( low_case== 'i' )
return true;
else if (low_case == 'o' )
return true;
else if (low_case == 'u' )
return true;
else
return false;

}

void changeLine (string line)//this is where the strings are changed. As long as there is
//not a Null character, changeling will look at each word. It will look for the blank spaces
//between the words. One a word is found it is the look at to whether it has a vowel in it or not
// then it is rearranged into a string.
{
string word, first;
char ch;
while (line.length() !=0)//line consist of characters
{
int wordLen = line.find(' ');
if (wordLen >0)
{
word = line.substr(0,wordLen);
first=word.substr(0,1);
ch = first[0];
string notFirst(word,1);
if (isVowels (ch))// vowel found
{
Vowel(word);
}
else
{
nonVowel(ch,notFirst);//no vowel found
}
line = line.substr(wordLen+1);
}
else
{
word = line;
ch = line[0];
string notFirst(word,1);
if (isVowels (ch))
Vowel(word);
else
nonVowel(ch, notFirst);
line="";
}
}
}
void Vowel(string changed)//what this does is when the string of the new word is brought in
//it is changed due to Pig latin configuration for words that begin with a vowel and then added "way" to the end of the word.
//this new word is then processed out to the string to put back to sentence form.
{
string newWord;
newWord=changed+"way";


for(int i=0;i<newWord.length();i++)
{
if(flag==0)
{
if(newWord[i]>='A'&&newWord[i]<='Z')
cout<<(char)(newWord[i]-'A'+'a');
else
cout<<newWord[i];
}
else
{
if(newWord[i]>='a'&&newWord[i]<='z')
cout<<(char)(newWord[i]-'a'+'A');
flag=0;
}
  
}
cout<<" ";

}

void nonVowel(char begin, string end)//what this does is when the string of the new word is brought in
//it is changed due to Pig latin configuration for words that do not begin
//with a vowel and then added "ay" to the end of the word.this new word is then processed
//out to the string to put back to sentence form.
{
string newWord;
newWord=end+begin;
if(!isVowels(newWord[0]))
{
string temp(newWord,1);
nonVowel(newWord[0],temp);
}
else
{
for(int i=0;i<newWord.length();i++)
{
  
  
if(flag==0)
{
if(newWord[i]>='A'&&newWord[i]<='Z')
cout<<(char)(newWord[i]-'A'+'a');
else
cout<<newWord[i];
}
else
{
if(newWord[i]>='a'&&newWord[i]<='z')
cout<<(char)(newWord[i]-'a'+'A');
flag=0;
}
  
  
}
cout<<"ay ";
}
  
}

Kindly revert for any queries

Thanks.


Related Solutions

Create a program that translates English into Pig Latin. The function will take the first letter...
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 ​ins​ ensitive. You must write the functiontranslate() ​that takes in a single English word and ​returns​ its Pig Latin translation. Remembertranslatemusttake​onlyonewordasinput.​ ############################################################# # translate() takes a single english word translates it to #pig latin...
Write a program that converts an English phrase into pseudo-Pig Latin phrase (that is Pig Latin...
Write a program that converts an English phrase into pseudo-Pig Latin phrase (that is Pig Latin that doesn't allow follow all the Pig Latin Syntax rules.) Use predefined methods of the Array and String classes to do the work. For simplicity in your conversion, place the first letter as the last character in the word and prefix the characters "ay" onto the end. For example, the word "example" would become "xampleay" and "method" would become "ethodmay." Allow the user to...
In C++ Language English/Spanish Translation Program. Create a menu driven program that translates English to Spanish...
In C++ Language English/Spanish Translation Program. Create a menu driven program that translates English to Spanish and Spanish to English. Your translation program should use arrays for this program. You will need to populate the arrays with the contents of the English and Spanish data files provided. The two files are ordered such that each word in the one file corresponds to the respective translation in the other (i.e.: the first word in the ENG.txt file corresponds to the first...
How do I write a COBOL program that translates a word entered into pig Latin?
How do I write a COBOL program that translates a word entered into pig Latin?
python Create a dictionary and insert several English words as keys and the Pig Latin (or...
python Create a dictionary and insert several English words as keys and the Pig Latin (or any other language) translations as values. Write a function called bonus that takes as a parameter a dictionary that has names as keys and salaries as values. Your function should increase everyone’s salary in the dictionary by 5%. Write a function called updateAge that takes as parameters a list of names of people whose birthday it is today, and a dictionary that has names...
In Java.This program will translate a word into pig-latin. Pig-latin is a language game in which...
In Java.This program will translate a word into pig-latin. Pig-latin is a language game in which words in English are altered, usually by removing letters from the beginning of a word and arranging them into a suffix. The rules we will use for the pig-latin in this program are as follows: If a word starts with a consonant, split the word at the first instance of a vowel, moving the beginning consonants to the end of the word, following a...
Use python write a function that translates the input string into Pig Latin. The translation should...
Use python write a function that translates the input string into Pig Latin. The translation should be done word by word, where all words will be separated by only one space. You may assume that each word must have at least one vowel (a,e,i,o,u and uppercased counterparts), and there will be no punctuation or other special characters in the input string. The Pig Latin rules are as follows: For words that begin with consonants, all letters before the initial vowel...
Pig Latin is a language constructed by transforming English words. The following rules are used to...
Pig Latin is a language constructed by transforming English words. The following rules are used to translate English into Pig Latin: *If the word begins with a consonant, then all consonants at the beginning of the word, up to the first vowel are removed then added to the end of the word, followed by “ay”. For example, “computer” becomes “omputercay” and “think” becomes “inkthay”. *If the word begins with a vowel, then “way” is added to the end of the...
Create a Visual Studio console project (c++) containing a main() program that declares a const int...
Create a Visual Studio console project (c++) containing a main() program that declares a const int NUM_VALUES denoting the array size. Then declare an int array with NUM_VALUES entries. Using a for loop, prompt for the values that are stored in the array as follows: "Enter NUM_VALUES integers separated by blanks:" , where NUM_VALUES is replaced with the array size. Then use another for loop to print the array entries in reverse order separated by blanks on a single line...
question: Pig LatinPig latin, is a mock language which encrypts english sentences using the following rules:...
question: Pig LatinPig latin, is a mock language which encrypts english sentences using the following rules: For every word in a sentence, the firstletter of the word is shifted to the end of the word and the suffix “-ay” is added at the end of the word. For example, “hey pat”becomes “eyhay atpay”.Implement thepiglatin(str)function so it translates sentences to pig latin. If you have time remaining, try implementing afunction to ”decrypt” piglatin, i.e. given a sentence in piglatin, return the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT