The program should work in c environment. For this exercise, write a program in
ID: 3615483 • Letter: T
Question
The program should work in c environment.For this exercise, write a program in c that translates from theEnglish language to another popular language "Pig Latin". For thisexercise, you will be using the following basic algorithm:
Consider the next word in the phrase.
Place the first letter of the word at the end of the word.
Add the letters ay or tay to the end of the word.
Continue until there are no more words.
For example, the above algorithm translated into Pig Latin wouldbe:
Onsidercay hetay extnay ordway nitay hetayhrasepay.
Lacepay hetay irstfay etterlay fotay hetay ordway tatay hetayndetay fotay hetay ordway.
Ddatay hetay etterslay yatay rotay aytay hetay ndetay fotay hetayordway.
ontinuecay ntilutay heretay reatay onay oremay ordsway.
Guildelines:
Although there are many different dialects of Pig Latin, theprogram will use the rules for the general modified universialdialect of the language:
1) if the English word begins with a consonant, then the firstletter is placed at the end of the word and the suffix "ay" isappended.
2) if the English word begin with a vowel, then the first letter isplaced at the end of the word and the suffix "tay" is appended.
3) if the English word is one character long, then the suffix "tay"is appended.
The program must be able to use correct punctuation andcaptitalization as shown in the above example. For example, theword "Place" should become "Lacepay" and not "lacePay" in order tokeep the capitalization and punctuation consistent. The onlypunctuation you need to worry about are period, commas, colons, andsemi-colons. You can assume that input text will not containquotation marks or apostrophes.
Implementation:
create two standard queues, implemented using singly linked lists,to hold your phrases.
The head pointer to the first queue should be named EnglishPhrase(or something similar),
and it should point to the head of a singly linked list containingthe original English phrase.
The head pointer to the second queue should be named PigLatinPhrase(or something similar),
and it should point to the head of a singly linked list containingthe translated Pig Latin phrase.
You will also need to write a menu-driven routine that will allowusers to test your program.
This menu should allow users to 1) input a phrase in English 2)translate the current phrase from English to Pig Latin 3) printeither the original phrase or the translated phrase to thescreen.
Below is a suggested struct definition for the individual nodes ofyour linked lists:
#define MAX_WORD_CHARS (30)
typedef struct WordNodeType
{
char word[MAX_WORD_CHARS];
struct WordNodeType *next;
}WordNode;
Whatever the definition for your node, will need to implement thefollowing functions;
WordNode* translateWord(WordNode* NextWord)
Precondition: NextWord is passed in as aparameter and points to a WordNode containing and English word.
Postcondition: A pointer to a new node containing the Pig Latintranslation of NextWord is returned to the calling function using areturn statement. NextWord remains unchanged.
void printPhrase(WordNode* Phrase)
Precondition: none
Postcondition: if phrase points to a valid linked list, all thewords contained in the list have been printed in the order thatthey appear in the list. If phrase is a NULL pointer, anappropriate mesage is printed.
Add whatever additional functions and variable you wish toimplement the program.
As long as properly implment the queues using linked lists of nodesallocated using memory from the heap, together with the above twofunctions, you may implement the remainder of your Pig Latintranslation program however you like. Just remember to useappropriate variables, constants, functions and coding.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LINELENGTH 80
#define WORDSEPARATORS ".,:; "
#define WORDSEP " "
int main()
{
int wordlength = 0;
char punctuation;
char* nextword;
char word[25];
char line[80];
char phrase[1000];
// You can use fgets to input a line of up to a specified size
printf("Enter a line of text: ");
fgets(line, 80, stdin); // up to 80 charactersread from stdin
if (strlen(line) <= 1)
printf("Sorry -- I cannot read your text.");
else
{ printf("Here is the line you input: %s", line);
printf("Now let's break up the line intowords! ");
nextword = strtok(line, WORDSEPARATORS);
printf(" Here is the first word in yourphrase: ");
printf("%s ", nextword);
printf(" Here is the second word in yourphrase: ");
nextword = strtok(NULL, WORDSEPARATORS);
printf("%s ", nextword);
}
// Alternatively, you can use gets to grab multiple lines atonce
printf("Enter as many lines as you like: ");
gets(phrase);
if (strlen(phrase) <= 1)
printf("Sorry -- I cannot read your text.");
else
{
printf("Here is your input: ");
printf("%s", phrase);
// Use strtok to separate your larger string into words.
// The first call will use the entire phrase as an argument.
// Getting future words using the same string requires sending NULLas the argument.
// Note that you will need to use a loop to get all words in thephrase.
nextword = strtok(phrase, WORDSEP); // getfirst word using strtok
printf("Here is the first word in yourphrase:");
printf("%s ",nextword);
printf("Here is the second word in yourphrase:");
nextword = strtok(NULL, WORDSEP); // useNULL as parameter for add'l words
printf("%s", nextword);
printf(" ");
}
// strlen tells you where to look for punctuation
wordlength = strlen(nextword);
if (!(isalpha(nextword[wordlength-1])))
{
punctuation = nextword[wordlength-1];
printf("Yourword had the punctuation %c following it! ", punctuation);
}
return 0;
}
Explanation / Answer
please rate- thanks best I can do #include #include #include int main() {int i,j; char str[80]; bool isvowel; int choice; char vowel[11]={"AEIOUaeiou"},first; char *in; FILE *file; char * pch; char wd[50]; printf("input from file or keyboard (1 for file 0 for keyboard)?"); scanf("%d",&choice); if(choice==1) if(!(file=fopen("input.txt","r"))) { printf(" Error opening file "); getch(); return 1; } if(choice==1) in=fgets(str,80,file); else { in=gets(str); } while(in!=NULL) {pch = strtok (str," ,.-?!;:"); while (pch != NULL) { isvowel=false; for(i=0;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.