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

Strings You have been asked to construct a program that will translate English t

ID: 3627280 • Letter: S

Question


Strings

You have been asked to construct a program that will translate English to Pig Latin. Following good programming practice, you
realize that the solution will make heavy use of functions. You plan to start by constructing a function that will convert an
English word into Pig Latin. Pig Latin is a fictitious language derived from English using a few simple rules.

1.) If a word starts with a vowel (a, A, e, E, i, I, o, O, u, U) then the translation is formed by adding a "way" to the end of
word. e.g. "at" becomes "atway", "egg" becomes "eggway"

2.) If a word contains no vowels (a, A, e, E, i, I, o, O, u, U) then the translation is formed by a adding a "way" to the end of
word. e.g. "my" becomes "myway", "by" becomes "byway"

3.) If a word starts with a consonant and contains a vowel, the translation is formed by moving the consonant(s) up to the first
vowel to the end of the word and adding an "ay". e.g. "bat" becomes "atbay", "that" becomes "atthay", "three" becomes "eethray"

4.) Words that start with an initial capital letter should be translated to words with an initial capital letter.
e.g. "Houston" becomed "Oustonhay", "Iceland" becomes "Icelandway", "Marry" becomes "Arrymay"


You will probably want functions to:
Input the word.
Find the length of a word.
Determine if a given letter is a vowel. (a helper function to make life easy for you)
Determine if a word starts with a vowel (rule 1).
Determine if a word contains a vowel (rule 2).
Determine where the vowel is in the word (rule 3).
Determine if the word has an initial capital letter (rule 4).
Output the English and Pig Latin words.

Explanation / Answer

please rate - thanks

message me if any problems

#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
int main()
{int i,j,up;
char str[80];
int choice,isvowel;
char vowel[11]={"AEIOUaeiou"},first,second;
char *in;
char * pch;
char wd[50];
printf("Enter a string ");
in=gets(str);

while(in!=NULL)
{up=0;
pch = strtok (str," ,.-?!;:");
if(isupper(pch[0]))
     up=1;
while (pch != NULL)
{ isvowel=0;
    for(i=0;i<10;i++)
        if(pch[0]==vowel[i])
            isvowel=1;
        if(isvowel)
              {for(j=0;j<strlen(pch);j++)
               if(pch[j]!=' ')
                  wd[j]=pch[j];
               wd[j]='';
               strcat(wd,"way");
              }
         else
            { for(i=0;i<10;i++)
                if(pch[1]==vowel[i])
                   isvowel=1;
            if(isvowel)
              {first=pch[0];
              for(j=1;j<strlen(pch);j++)
                 if(pch[j]!=' ')                     
                     wd[j-1]=pch[j];
              if(pch[j]==' ')
                   j--;
               wd[j-1]=first;              
               wd[j]='';
               strcat(wd,"ay");             
               }
             else
                {first=pch[0];
                second=pch[1];
              for(j=2;j<strlen(pch);j++)
                 if(pch[j]!=' ')                     
                     wd[j-2]=pch[j];
              if(pch[j-1]==' ')
                   j--;
               wd[j-2]=first;
               wd[j-1]=second;             
               wd[j]='';
               strcat(wd,"way");             
               }
              }
    if(up==1)
        wd[0]=toupper(wd[0]);     
    for(j=0;j<strlen(wd);j++)
        {if(j>0&&isupper(wd[j]))
              wd[j]=tolower(wd[j]);
       
        }
     printf ("%s %s ",pch,wd);   
    
    pch = strtok (NULL, " ,.-?!;:");
}
printf(" ");
printf("Enter a string (CTRL^Z enter to exit)");
in=gets(str);

}
return 0;
}