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

Programme should be written in C Write a program that encodes English-language p

ID: 3860912 • Letter: P

Question

Programme should be written in C

Write a program that encodes English-language phrases into pig Latin. Pig Lat- in is a form of coded language often used for amusement. Many variations exist in the methods used to form pig-Latin phrases. For simplicity, use the following algorithm: To form a pig-Latin phrase from an English-language phrase, tokenize the phrase into words with function strtok. To translate each English word into a pig-Latin word, place the first letter of the English word at the end of the English word and add the letters "ay." Thus the word "jump" becomes "umpjay, " the word "the" becomes "hetay" and the word "computer" becomes "omputercay." Blanks between words remain as blanks. Assume the following: The English phrase consists of words separated by blanks, there are no punctuation marks, and all words have two or more letters. Function printLatinword should display each word.

Explanation / Answer

The required code is as follows as per the description. Here we go..

EngToPig.c

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

void init(char eng[], char pigL[]);
void inputs(char eng[]);
int cnt(char eng[]);
void cnv(int wrd, char eng[], char pigL[]);
void out(char pigL[]);

main( )
{
char eng[80], pigL[80];
int wrd;
printf(" Pig Latin Translator in C ");
printf( "Type 'END' when finished ");

do
{
init(eng, pigL);
inputs(eng);

if (toupper(eng[0]) == 'E' && toupper(eng[1]) == 'N' && toupper(eng[2]) == 'D')
break;

wrd = cnt(eng);

cnv(wrd, eng, pigL);
out(pigL);
}
while (wrd >= 0);
printf(" aveHa aa icena ayda (Have a nice day) oq");
}


void init(char eng[], char pigL[])
{
int cntq;
for (cntq = 0; cntq < 80; ++cntq)
eng[cntq] = pigL[cntq] = ' ';
return;
}


void inputs(char eng[])
{
int cntq = 0;
char ch;
while (( ch = getchar()) != ' oq')
{
eng[cntq] = ch;
++cntq;
}
return;
}


int cnt(char eng[])
{
int cntq, wrd = 1;
for (cntq = 0; cntq < 79; ++cntq)
if (eng[cntq] == ' ' && eng[cntq + 1] != ' ')
++wrd;
return (wrd);
}


void cnv(int wrd, char eng[], char pigL[])
{
int noq, cntq;
int x1 = 0;
int x2;

for (noq = 1; noq <= wrd; ++noq)
{
cntq = x1 ;
while (eng[cntq] != ' ')
x2 = cntq++;

for (cntq = x1 ; cntq < x2; ++cntq)
pigL[cntq + (noq - 1)] = eng[cntq + 1];
pigL[x2 + (noq - 1)] = eng[x1];
pigL[x2 + noq] = 'a'; /* adding 'a' at the end */

x1 = x2 + 2;
}
return;
}


void out(char pigL[])
{
int cntq = 0;
for (cntq = 0; cntq < 80; ++cntq)
putchar(pigL[cntq]);
printf(" ");
return;
}

Please rate the answer if it helped.....Thankyou

Hope it hleps....