Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A language game, such as Pig Latin, alters spoken words to make them incomprehen

ID: 3668657 • Letter: A

Question

A language game, such as Pig Latin, alters spoken words to make them incomprehensible to the untrained ear. Write a c++ 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.

** Already submitted just need to add some corrections based on the following:

-Need to add comments for functions besides int main()

-Be able to parse a phrase or sentence (one token at a time)

Here is the following code that I had, feel free to use or change it up. Otherwise those two items above are all that needs to be addressed.

#include<iostream>

#include<string>

using namespace std;

void game(const char* arr) {

int i, j; // initializing variables

for (i = 0; i<strlen(arr); i++) { // Checking consonants

if (arr[i] == 'a' || arr[i] == 'e' || arr[i] == 'i' || arr[i] == 'o' || arr[i] == 'u') {

break;

}

}

for (j = i; j<strlen(arr); j++) cout << arr[j]; // rearanging word

cout << "-";

for (j = 0; j<i; j++) cout << arr[j];

cout << "ay"; // ads ay to end of the word

cout << endl;

}

int main() {

string word;

cout << "Enter a word to be translated to Pig Latin: "; // Prompts user for word

cin >> word; // inputs the users word choice

game(word.c_str());

system("PAUSE");

return 0;

}

Explanation / Answer

Here is the Working code for the sentense

#include<iostream>
#include<cstring>
#include<string>

using namespace std;

void game(const char* arr) {

int i, j; // initializing variables

for (i = 0; i<strlen(arr); i++) { // Checking consonants

if (arr[i] == 'a' || arr[i] == 'e' || arr[i] == 'i' || arr[i] == 'o' || arr[i] == 'u') {

break;

}

}

for (j = i; j<strlen(arr); j++)
cout << arr[j]; // rearanging word

cout << "-";

for (j = 0; j<i; j++) cout << arr[j];

cout << "ay"; // ads ay to end of the word

cout << endl;

}

int main() {

string word;

cout << "Enter a word to be translated to Pig Latin: "; // Prompts user for word

getline(cin,word); // inputs the users word choice

string strWords[5];
short counter = 0;

for(short i=0;i<word.length();i++){
    if(word[i] == ' '){
        counter++;
        i++;
    }
    strWords[counter] += word[i];
}

for(short i=0;i<=counter;i++)
{
cout<<" ";
game(strWords[i].c_str());
}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote