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

********************** IN C PLEASE *************************** *****************

ID: 3817278 • Letter: #

Question

********************** IN C PLEASE ***************************

********************** // COMMENTS INCLUDE IF POSSIBLE**********

1st problem-

PROBLEM # 2

THANK YOU VERY MUCH IN ADVANCED!!!!

For this assignment, you will write a function that converts a single English word to its pig Latin equivalent. That function should have a header as follows: char convert PigLatin (char engstr, char pLatinstr) You'll note that it takes two char as input and returns a char as expected. The two inputs are pointers to the English string and the converted Pig Latin string respectively. The return value should be a pointer to the Pig Latin string. That return value can then be assigned to a variable and used to print out the converted string, either to the console or to a file. Your program should then perform the following steps 1) Open a file for input called pigLatinIn txt, which will be provided to you. This file will consist of one English word per line. 2) Open a file for output called pigLatinout. txt. 3) Your program will then read the input file, use the convertToPigLatin function. to determine the pig Latin equivalent to the word, then write the following to the output file English word Pig Latin Word abin-cay cabin apple apple 4) Print out the results in all lower case.

Explanation / Answer

Here is the code for the first problem:

#include <stdio.h>
#include <string.h>

int posFirstVowel(char inStr[])
{
    for(int i = 0; i < strlen(inStr); i++)
    {
       switch(inStr[i])
       {  
          case 'A':
          case 'a':
          case 'E':
          case 'e':
          case 'I':
          case 'i':
          case 'O':
          case 'o':
          case 'U':
          case 'u':   return i;
       }
    }
    return -1;
}
void convertToPigLatin(char inStr[], char pigLatin[])
{
    int firstVowelPosition = posFirstVowel(inStr);
    if(firstVowelPosition == 0)
    {
        strcpy(pigLatin, inStr);
        strcat(pigLatin, "-way");
    }  
    else
    {
       char residualString[30];
       strcpy(residualString, inStr + firstVowelPosition);
       char consString[30];
       strcpy(consString, inStr);
       consString[firstVowelPosition] = '';
       strcat(residualString, "-");
       strcat(residualString, consString);
       strcat(residualString, "ay");
       //return residualString + "-" + consString + "ay";
    }  
}
int main()
{
    FILE *fin = fopen("pigLatinIn.txt", "r");
    if(fin == NULL)
    {
       printf("Unable to open the input file... Quitting..... ");
       return 0;
    }
    FILE *fout = fopen("pigLatinOut.txt", "w");
    if(fout == NULL)
    {
       printf("Unable to open the output file... Quitting..... ");
       return 0;
    }
    fprintf(fout, " English word Pig Latin word ");
    //fout << " English word Pig Latin word" << endl;
    while(!feof(fin))
    {
       char word[30], pigLatinWord[30];
       fscanf(fin, "%s", word);
       //fin >> word;
       convertToPigLatin(word, pigLatinWord);
       fprintf(fout, "%15s %15s ", word, pigLatinWord);
       //cout << setw(15) << word << " " << setw(15) << convertToPigLatin(word) << endl;
       //fout << setw(15) << word << " " << setw(15) << convertToPigLatin(word) << endl;
    }  
}