In: Computer Science
Write a program that converts an English phrase into pseudo-Pig Latin phrase (that is Pig Latin that doesn't allow follow all the Pig Latin Syntax rules.) Use predefined methods of the Array and String classes to do the work. For simplicity in your conversion, place the first letter as the last character in the word and prefix the characters "ay" onto the end. For example, the word "example" would become "xampleay" and "method" would become "ethodmay." Allow the user to input the English phrase. After converting it, display the new Pig Latin phrase. Submit to the Assignment folder the zipped source file of your project. Must be in C#.
Code:-
//Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PigLatin
{
class Program
{
static void Main(string[] args)
{
string usertext = "";
Console.WriteLine("\n\n\tC# program that converts English Phrase to
Pig Latin");
Console.Write("Enter your text : ");
//Read an input text from console
usertext = Console.ReadLine();
//Call method toPigLatin with usertext
string piglatin = toPigLatin(usertext);
//Print the piglatin string on console
Console.WriteLine("Converted Pig Latin : {0}", piglatin);
Console.ReadKey();
}
/*The method toPigLatin that takes a string as input argument
and then find the translated pig latin of each word in a string
separated
* by space or tab .Returns the tranlated string to "main"
method
*/
public static string toPigLatin(string str)
{
char[] whitespace = new char[] { ' ', '\t' };
string[] words=str.Split(whitespace );
string result = "";
for (int i = 0; i < words.Length ; i++)
{
string temp = words[i];
char ch = temp[0];
result = result+temp.Substring(1, temp.Length-1) + ch + "ay" + "
";
}
return result;
}//end of the method, toPigLatin
}
}//end of the class
Output:-
Please UPVOTE thank you...!!!