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

Sixth: Pig Latin (10 Points) For this part of the assignment, you will need to w

ID: 3755353 • Letter: S

Question

Sixth: Pig Latin (10 Points) For this part of the assignment, you will need to write a program that reads an input string representing a sentence, and convert it into pig latin. We'll be using two simple rules of pig latin: 1. If the word begins with a consonant then take all the letters up until the first vowel and put them at the end and then add "ay" at the end 5 2. If the word begins with a vowel then simply add "yay" to the end For this problem vowels are defined as: a, e, i, o, and u. There will only be characters in your input (no numbers or punctuation) Input-Output format: This program takes a string of space-separated words and should output the same space-separated words translated into pig latin. Example 1: $./sixth Hello and welcome to computer architecture elloHay andyay elcomeway otay omputercay architectureyay Example 2 $./sixth a program ayay ogrampray

Explanation / Answer

ScreenShot

-------------------------------------------------------

Program

//Header files for string operation and I/O
#include<stdio.h>
#include<string.h>
int main()
{
   //For sentence
   char sentence[100];
   //For each word
   char word[100];
   //Variables for looping
   int i= 0,j=0;
   //Prompt for sentence
   printf("Enter a sentence: ");
   //Read sentence
   scanf("%[^ ]s", sentence);
   //Take each word sepaerated by delimitter
   char* token = strtok(sentence, " ");
   while (token != NULL) {
       //Copy each token or word into word array
       strcpy(word, token);
       //Check the first letter vowel or not
       //If alphabet print the word and then print yay at the end
       if (word[0] == 'a' || word[0] == 'A' || word[0] == 'e' || word[0] == 'E' || word[0] == 'i' || word[0] == 'I' || word[0] == 'o' || word[0] == 'O' || word[0] == 'u' || word[0] == 'U') {
           for (i = 0; i < strlen(word); i++) {
               printf("%c", word[i]);
           }
           printf("%c", 'y');
           printf("%c", 'a');
           printf("%c ", 'y');
       }
       //Not vowel
       else {
           for (i = 1; i < strlen(word); i++) {
               //Find until vowel the print
               if (word[i] == 'a' || word[i] == 'A' || word[i] == 'e' || word[i] == 'E' || word[i] == 'i' || word[i] == 'I' || word[i] == 'o' || word[i] == 'O' || word[i] == 'u' || word[i] == 'U') {
                  
                   for (j = i; j < strlen(word); j++) {
                       printf("%c", word[j]);
                   }
               }
               //After that print from start
               for (j = 0; j < i; j++) {
                   printf("%c", word[j]);
               }
               //Then add "ay" at the end
               printf("%c", 'a');
               printf("%c ", 'y');
               break;
           }
       }
       //Take each word
       token = strtok(NULL, " ");
   }
   //End of the program
   printf("%s", " ");
    return 0;
}

-------------------------------------------------

Output

Enter a sentence: Hello and welcome to computer architecture
elloHay andyay elcomeway otay omputercay architectureyay
Press any key to continue . . .

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