Write a function, called ToPigLatin, which is described below: 1-This function r
ID: 3634451 • Letter: W
Question
Write a function, called ToPigLatin, which is described below:1-This function receives a string object (word) as a parameter, passed by const reference (so that the original won't change).
2-You are to define this function so that it returns a string object that is the "Pig Latin" translation of the original incoming string (word)
If a word starts with a vowel, the Pig Latin version is the original word with "way" added to the end
If a word starts with a consonant, or a series of consecutive consonants, the Pig Latin version transfers all consonants up to the first vowel to the end of the word, and adds "ay" to the end.
The letter 'y' should be treated as a consonant if it is the first letter of a word, but treated as a vowel otherwise.
Optional BONUS feature, for Extra Credit: If the original word is capitalized, the new Pig Latin version of the word should be capitalized in the first letter (i.e. the previous capital letter may not be capitalized any more).
In the starter file is a main() program that I have already provided you with for testing. This program prompts the user to type in 5 words, then it calls the function for each of them and prints the converted version of each of the 5 strings. Note that the main() function does all of the output -- your function should do NO output (just the appropriate conversion and return). The output from your test runs should match mine exactly. Do not change the main() program in any way.
Sample Runs
(user input is underlined, to distinguish it from output)
Sample Run 1
Input 5 words: Flower yellow bypass apple Igloo
Pig Latin version of the 5 words:
Owerflay ellowyay ypassbay appleway Iglooway
Sample Run 2
Input 5 words: string Hamburger Rhythm queen zippitydoodah
Pig Latin version of the 5 words:
ingstray Amburgerhay Ythmrhay ueenqay ippitydoodahzay
------------------------I FINISH THE PROGRAM BUT STUCK ON THIS PARTThe letter 'y' should be treated as a consonant if it is the first letter of a word, but treated as a vowel otherwise.
Optional BONUS feature, for Extra Credit: If the original word is capitalized, the new Pig Latin version of the word should be capitalized in the first letter (i.e. the previous capital letter may not be capitalized any more).
Explanation / Answer
#include #include #define MAX_LINE_LEN 81 void translate_sentence (char *c) { while (strchr("aeiouAEIOU",*c) == NULL) { char consonant = *c; char *to = c, *from=c+1; while (*to++ == *from++) { consonant = *to; } } printf("%say", c); } int main (int argc, char *argv[]) { char sentence[MAX_LINE_LEN]; char *word; puts("This program translates your sentence into pig latin."); printf("Please type in a sentence or type stop: "); fgets(sentence,MAX_LINE_LEN,stdin); *(strchr(sentence, ' ')) = ''; printf("You typed in %s ", sentence); word = strtok(sentence, " "); translate_sentence(word); printf(" "); return 0; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.