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

2. Write a program to read a file and write it back to another file converted to

ID: 3548341 • Letter: 2

Question

2. Write a program to read a file and write it back to another file
converted to Pig Latin

The rules for piglatin are:

1. In words that begin with consonants, the initial consonant or
consonant cluster is moved to the end of the word, after a dash,
an "ay" is added, as in the following examples:

* happy -> appy-hay
* strait -> ait-stray

2, In words that begin with vowels, the syllable "-way" is simply
added to the end of the word, as in the following examples:

* another -> another-way
* about -> about-way

3. If the word ends with a punctuation mark the punctuation remains
at the end of the word, as in the following examples:

* happy! -> appy-hay!
* strait? -> ait-stray?
* about. -> about-way.

Note:
A, E, I, O, and U (upper or lower case) are considered vowels
ALL others are considered consonants.



Note: You may either use the C# string member function Split or the code
for exercise 1 to separate the file into words.

Note: You may use the C# Char.IsWhiteSpace and Char.IsPunctuation Methods
or you can write your own. You must write an isVowel Method.

Explanation / Answer

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;


namespace FunctionTest

{

public class Program

{

public static void pigTalk(string sentence)

{

try

{

while (sentence != "exit")

{

string firstLetter;

string afterFirst;

string pigLatinOut = "";

int x;

string vowel = "AEIOUaeiou";


string[] pieces = sentence.Split();


foreach (string piece in pieces)

{

afterFirst = piece.Substring(1);

firstLetter = piece.Substring(0, 1);

x = vowel.IndexOf(firstLetter);


if (x == -1)

{

pigLatinOut = (afterFirst + firstLetter + "ay ");

}

else

{

pigLatinOut = (firstLetter + afterFirst + "way ");

}

Console.Write(pigLatinOut);

}

}

}

catch (Exception e)

{

Console.WriteLine(e.ToString());

}

}

}

}


public static void Main(string[] args)

{

Console.WriteLine("Enter a sentence to convert into PigLatin");

string sentence = "";


sentence = Console.ReadLine();


Program.pigTalk(sentence);

}

  

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